Amazon.com

  www.amazon.com
Work in HR? Unlock Free Profile

Amazon.com Software Development Engineer Intern Interview Question

I interviewed in Seattle, WA and was asked:
"Reverse a linked list - both iterative and recursive way."
Add Tags [?]
Answer

Part of a Software Development Engineer Intern Interview Review - one of 4,667 Amazon.com Interview Reviews

Answers & Comments

0
of 0
votes

Node reverse(Node head) {

    Node temp;
    Node previous = NULL;
    while (head != NULL) {
         temp = head.next;
         head.next = previous;
         previous = head;
         head = temp;
    }
    return previous;
}

- Anon on Dec 4, 2013
0
of 0
votes

void reverse(Node* & curr)
{
    if(!curr)
        return;

    Node* p=curr->next;
        if(!p)
            return;

    reverse(p);
    curr->next->next=curr;
    curr->next=NULL;
    curr=p;
}

- anonymous on Jan 9, 2014

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.