Cisco Systems Interview Question: Reverse a Linked List... | Glassdoor

Interview Question

Software Engineer Interview San Jose, CA

Reverse a Linked List

Answer

Interview Answer

2 Answers

0

I really don't think Reverse a Linked List is hard question.

Anonymous on Feb 18, 2016
0

Need guides on Technical Interview? - Algorithm/ System Design / Problem Solving / Mock Interviews / Behavioral Training

Visit aonecode.com

Get one-on-one coaching and feedback from engineers|interviewers at Google, Fb and Uber.

Email us aonecoding@gmail.com with any questions. Thanks!

SOLUTION
public ListNode reverse(ListNode head) {
    ListNode prev = null;
    while (head != null) {
        ListNode next = head.next;
        head.next = prev;
        prev = head;
        head = next;
    }
    return prev;
}

AONECODE.COM on Aug 27, 2018

Add Answers or Comments

To comment on this, Sign In or Sign Up.