O(n) solution using Queue in Java.
\n# Approach\n- Find words in dictionary, adding 1 character at a time. Add such words to queue and iterate. If the queue gets empty we can\'t move forward anym
\n# Approach\n- Find words in dictionary, adding 1 character at a time. Add such words to queue and iterate. If the queue gets empty we can\'t move forward anymore by 1 character, then return answer. Adding characters z->a, to get lexicographically smaller word.\n\n# Complexity\n- Time complexity:\nO(n) :  For each word in the array, we iterate 26 times to find words in dictionary adding 1 character. Therefor it will be run in O(26n) ~ O(n). \n\n- Space complexity:\nO(n) for HashSet.\n\n# Code\n```\nclass Solution {\n    public String longestWord(String[] words) {\n        Set<String> set = new HashSet<>();\n\n        for(int i = 0; i < words.length; i++){\n            set.add(words[i]);\n        }\n\n        Queue<String> q = new LinkedList<>();\n\n        q.add("");\n        String prev = "";\n\n        while(!q.isEmpty()){\n            String s = q.poll();\n            prev = s;\n            for(int i = 25; i >=0 ; i--){\n                String key = s + String.valueOf((char) (\'a\' + i));\n                if(set.contains(key)){\n                    q.add(key);;\n                }\n            }\n        }\n        return prev;\n    }\n}\n```
['Java']