java using TRIE (simple solution)
\nclass Node{\n    Node links[]=new Node[26];\n    int end=0;\n    Node(){}\n    //checking whther char is already present in trienode or not\n    boolean conta
```\nclass Node{\n    Node links[]=new Node[26];\n    int end=0;\n    Node(){}\n    //checking whther char is already present in trienode or not\n    boolean containsKey(char ch){\n        return (links[ch-\'a\']!=null);\n    }\n    //creating new node from char\n    void put(char ch ,Node node){\n        links[ch-\'a\']=node;\n    }\n    //returning value of node\n    Node get(char ch){\n        return links[ch-\'a\'];\n    }\n    //setting the end of each word\n    void setEnd(){ \n        end=1;\n    }\n    int getEnd(){\n        return end;\n    }\n}\n//trie class\nclass Trie{\n    Node root;\n    Trie(){\n        root=new Node();\n    }\n    //inserting each character of word\n    public void insert(String word){\n        Node node=root;\n        for(int i=0;i<word.length();i++){\n            if(!node.containsKey(word.charAt(i))){\n                node.put(word.charAt(i),new Node());\n            }\n            node=node.get(word.charAt(i));\n        }\n        node.setEnd();\n    }\n    //checking that my current string ends with 1 with its all characters\n    public boolean iscorrect(String word){\n        Node node=root;\n        for(int i=0;i<word.length();i++){\n            node=node.get(word.charAt(i));\n            if(node.getEnd()==0){\n                return false;\n            }\n            \n        }\n        return node.getEnd()==1?true:false;\n    }\n}\nclass Solution {\n    public String longestWord(String[] words) {\n        Trie obj=new Trie();\n        for(String x:words){\n            obj.insert(x);\n        }\n        String lon="";\n        for(String x:words){\n      \n            if(obj.iscorrect(x)){\n                if(x.length()>lon.length()){\n                    lon=x;\n                }\n                //when string len equals checking which is lexicographically smaller\n                else if(x.length()==lon.length() && x.compareTo(lon)<0){\n                    lon=x;\n                }\n            }\n        }\n        return lon;\n    }\n}\n```\n***please upvote if you like my solution~***
['Trie']