Akamai Interview Question
Java DevelopersCountry: India
Interview Type: In-Person
I think avikodak's solution would be a good choice if would be important to not use any additional space.
But since the important thing is minimum time complexity .. we can do it in O(n * w) where word is the length of the word : we would use the same logic as in avikodak's algorithm, but in stead of using a n log n sorting alg. I would recommend counting alg which we'll involve additional space , but we'll decrease the time complexity.
Use a hash map (hash_map<string,list<string>). The key for the hash map will be the sorted form of the scanned word.If the key doesnt exists in the hash map then create a list and the append the word to the list . This list serves as the value.If the key exists then append the scanned word for the list
- avikodak December 15, 2012