Challenge 5: Reverse a Linked List
Can you implement a program which could reverse a linked list? Let's find out!
We'll cover the following
Problem statement
You have to write the Reverse
function, which starts iterating from the head and swaps nodes of the list, so that in the end, it returns a string that contains a reversed list.
Input
The input is a linked list.
Output
The reversed linked list is the output.
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 80+ hands-on prep courses.