3.3 of 5 3,204 reviews Seattle, WA 5000+ Employees Software Development Engineer Co-Op Interview Question

I interviewed in Seattle, WA and was asked:
"How to print a link list reversely"
Tags: data structures
Add Tags [?]
Answer Flag Question

Part of a Software Development Engineer Co-Op Interview Review - one of 4,605 Interview Reviews

Answers & Comments

of 2
The simplest solution would be:

1. Traverse a linked list from head to tail
2. During traversal, push all the elements of the node into a stack
3. Once the traversal is done, pop all elements and this will print the linked list in reverse order ...

Looking fwd for an optimized solution ...
- Vikas on Jun 16, 2012 Flag Response
of 0
void printLLreverse(Node *headNode)
    //this is going to just iterate through the LL
    //add each element to a stack and
    //print the stack when we are finished
    stack <int> llStack;
    Node* currNode = headNode;
        currNode = currNode->next;
    while(llStack.size() > 0)
        cout <<;
- anonymous on Sep 25, 2012 Flag Response
of 0
the stack solution is good, you can also use recursion
void printReverse(ListNode node) {
    if(node == null)
- helloslz on Dec 29, 2013 Flag Response

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.

Glassdoor is your free inside look at interview questions and advice. All interview reviews posted anonymously by employees and interview candidates.