Amazon Interview Question
Software Engineer / Developers@Rohan: I accept with u. Each movement of snake need to be searched for existence of that new covered point in its list. This costs O(snake length). Its better to have extra hash as well. so searching can be done quickly.
Finally, LL for order of points covered by snake and hash to search for correctness.
A Linked list.(Each node can point to the previous and next node).It is easier to add nodes to the end of a linked list. If you use an array you would either need to resize it or initialise it to the maximum possible snake length to start(which is a waste of memory)
- Rohan July 25, 2011