Pergunta de entrevista da empresa Meta

Reverse a linked list (warm up question).

Respostas da entrevista

Sigiloso

23 de ago. de 2012

Node* reverseLL(Node* n) { Node* curr = n; Node* prev = null; while(curr !=null) { Node* temp = curr.next; curr.next = prev; prev = curr; curr = temp; } return prev; }

4

Sigiloso

9 de nov. de 2012

This is in PHP function reverseLinkedListRecursive($current, $second){ if($second->next == null){ $second->next = $current; return $second; } else { $node = reverseLinkedListRecursive($second, $second->next); $second->next = $current; return $node; } }

1

Sigiloso

1 de jan. de 2013

//If additional buffer is allowed then use a Stack. 1) iterate through the linked-list and add each node values to a stack, 2)iterate again through the linked-list and replace the node values with the values of the stack(starting from top of the stack )using pop operation.