Java solution (easy to understand)
\n    public String longestWord(String[] words) {\n        Arrays.sort(words);\n        Set<String> set = new HashSet<String>();\n        String max = "";\n    
```\n    public String longestWord(String[] words) {\n        Arrays.sort(words);\n        Set<String> set = new HashSet<String>();\n        String max = "";\n        for (int i = 0; i < words.length; i++) {\n            if (words[i].length() == 1 || set.contains(words[i].substring(0, words[i].length() - 1))) {\n                set.add(words[i]);\n                if (max.length() < words[i].length()) max = words[i];\n            }\n        }\n        return max;\n    }\n```
[]