Amazon Interview Question
Software Engineer / DevelopersLinked List?? If you're reading from a stream, you're gonna traverse the linked list every time you read an integer from the stream to check and possibly update the occurrence of that integer? Grossly inefficient isn't it?
If the set of integers is known, then the problem becomes simple.
- ola April 19, 2007If the set of integers is known:
Have a hash of the known set of integers. Parse the input stream, hash it to get the key and increase its corresponding value.
If the set of integers is unknown:
Use a linked list instead of an array for your hash.