Pergunta de entrevista da empresa Amazon

1. Find out that data in a linked list is a palindrome

Respostas da entrevista

Sigiloso

4 de mar. de 2012

1) Traverse the linked list .put the nodes on the stack. 2) Traverse the linked list second time and pop the node from stack.Compare them. if equal repeat 2 until stack is empty else linked list is not palindrome.

5

Sigiloso

27 de jan. de 2012

Put all the values in the linklist into a hashmap with each spot equal to its location on the linked list then using two pointers, one at 1 and the other at size of the link list compare the values at both pointers if equal, add one to the smaller one and remove one from the other compare the values at both pointers do until both pointer value are the same or values at the pointer are not equal.

2

Sigiloso

29 de mar. de 2012

I would try to see what type of linked list it is. If singly, the stack method would work well. For doubly, traverse to the end of the list and compare it to the front. Traverse inwards until left node equals the right node.

1