Amazon Interview Question
Applications DevelopersCountry: India
You can do this using HashMap<String,Boolean>. Store these 'I' words in a HashMap and pick work by from a newspaper and check whether the picked words is present in HashMap or not if its present mark it true in Value part of HashMap this way do it for all the words. If the all words value is true than the give set of words are there in Newspaper....
Please share if have any other answer with better time and space complexity
Thank you.
make a trie tree of i words. then scan through the paper once. for every hit in trie we increase the value for that i key. (we have to specify a condition in trie. that we can only update those nodes which are instantiated to 0 and we cannot increase or touch the none nodes.. )
- ashish.singla87 July 25, 2012