Google Longest word in Dictionary Question

Hey there, there's this question here https://techdevguide.withgoogle.com/resources/former-interview-question-find-longest-word/ and I can't understand the last optimal solution provided by Google,

a -> [("able", 0), ("ale", 0), ("apple", 0)]
b -> [("bale", 0)]
k -> [("kangaroo", 0)]

Wouldn't this take extra time to match the first character of every string and add it to its relevant list in the hash map ?
Also I tried to run their solution, and it has syntax error in Python. I'd really appreciate the help !

Comments (2)