Challenge: Reverse a Linked List

Can we implement a program which could reverse a linked list? Let's find out.

Problem Statement #

You have to write the reverse function, which starts iterating from the head and swap nodes of the list, such that, in the end, it returns a string which contains a reversed list.

Input #

A linked list.

Output #

The reversed linked list.

Sample Input #

LinkedList = 0->1->2->3-4

Sample Output #

LinkedList = 4->3->2->1->0


Level up your interview prep. Join Educative to access 70+ hands-on prep courses.