C++ || TRIE
\nclass Solution {\npublic:\n    struct Node{\n        Node* children[26];\n        bool end;\n    };\n    Node* getNode()\n    {\n        Node* temp = new Node
```\nclass Solution {\npublic:\n    struct Node{\n        Node* children[26];\n        bool end;\n    };\n    Node* getNode()\n    {\n        Node* temp = new Node();\n        for (int i = 0;i < 26;i++)\n            temp -> children[i] = NULL;\n        temp -> end = false;\n        return temp;\n    }\n    \n    void insert(string s, Node* root)\n    {\n        Node* temp = root;\n        int n = s.size();\n        for (int i = 0; i < n; i++)\n        {\n            if (!temp -> children[s[i] - \'a\'])\n                temp -> children[s[i] - \'a\'] = getNode();\n            temp = temp->children[s[i] - \'a\'];\n        }\n        temp -> end = true;\n    }\n    string comp(string a, string b)\n    {\n        if (a.size() > b.size())\n            return a;\n        else if (a.size() < b.size())\n            return b;\n        else if (a.size() == b.size())\n        {\n            for (int i = 0; i < a.size(); i++)\n            {\n                if (a[i] < b[i])\n                    return a;\n                else if (b[i] < a[i])\n                    return b;\n            }\n        }\n        return NULL;\n    }\n    string compute(Node* root, string s)\n    {\n        string temp = s;\n        string ans = temp;\n        for (int i = 0; i < 26; i++)\n        {\n            if (root -> children[i] && root -> children[i] -> end)\n            { \n                ans = comp(ans,\n                           compute(root->children[i], temp + char(i + \'a\'))\n                          );\n            }\n        }\n        return ans;\n    }\n    string longestWord(vector<string>& words) {\n        int n = words.size();\n        Node* root = getNode();\n        for (int i = 0; i < n; i++)\n            insert(words[i], root);\n        string ans = compute(root, "");\n        return ans;\n    }\n};\n```
[]