<p>Write a function to find the longest common prefix string amongst an array of strings.</p>

<p>If there is no common prefix, return an empty string <code>&quot;&quot;</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> strs = [&quot;flower&quot;,&quot;flow&quot;,&quot;flight&quot;]
<strong>Output:</strong> &quot;fl&quot;
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> strs = [&quot;dog&quot;,&quot;racecar&quot;,&quot;car&quot;]
<strong>Output:</strong> &quot;&quot;
<strong>Explanation:</strong> There is no common prefix among the input strings.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= strs.length &lt;= 200</code></li>
	<li><code>0 &lt;= strs[i].length &lt;= 200</code></li>
	<li><code>strs[i]</code> consists of only lowercase English letters.</li>
</ul>

class Solution;
class Node{
    char data;
    int rep;
    unordered_map<char, Node*> m;
    bool isTerminal;
    public:
        Node(char d){
            data = d;
            rep = 0;
            isTerminal = false;
        }

        friend class Solution; 
};

class Solution {
Node* root;
public:
    Solution(){
        root = new Node('\0');
    }

    // Prefix{
    string longg(Node* tmp,int limit, string ab){
        // Node* tmp = root;
        for(auto x:tmp->m){
            // cout<<x.first<<" "<<x.second->rep<<endl;
            if(x.second->rep == limit){
                ab.push_back(x.first);
                ab = longg(x.second,limit,ab);
                return ab;
            }
        }
        // cout<<tmp->m.size()<<" "<<tmp->rep<<endl;
        return ab;
    }

    //  Insertion
    void insert(Node* tmp, string word){
        // Node* tmp = root;
        for(char ch: word){
            if(tmp->m.count(ch) == 0){
                Node* n = new Node(ch);
                tmp->m[ch] = n;
            }
            tmp = tmp->m[ch];
            tmp->rep++;
            // cout<<tmp->data<<" "<<tmp->rep<<endl;
        }
        tmp->isTerminal = true;

        
    }



    string run(vector<string> strs){
        Node* tmp = root;
        Solution n;
        for(auto s: strs){
            n.insert(tmp,s);
        }   

        string ac = "";
        // Node* tmp = root;
        return longg(tmp, strs.size(), ac);
    }

    string longestCommonPrefix(vector<string>& strs) {
        // Solution n;
        // Node* tmp = root;
        // for(auto s: strs){
        //     n.insert(s);
        // }

        

        return run(strs);


    }
};
13700