Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Reverse Linked List
MEDIUM
15 mins
297 upvotes
Stacks & Queues
Linked List
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Linked List
-
-
Stacks & Queues
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Sorting
-
-
Binary Search
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Reverse Linked List

Contributed by
Ashwani
Medium
yellow-spark
0/80
Avg time to solve 15 mins
Success Rate 85 %
Share
297 upvotes

Problem Statement

Given a singly linked list of integers. Your task is to return the head of the reversed linked list.

For example:
The given linked list is 1 -> 2 -> 3 -> 4-> NULL. Then the reverse linked list is 4 -> 3 -> 2 -> 1 -> NULL and the head of the reversed linked list will be 4.
Follow Up :
Can you solve this problem in O(N) time and O(1) space complexity?
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1 :
1
1 2 3 4 5 6 -1
Sample Output 1 :
6 5 4 3 2 1 -1
Explanation For Sample Input 1 :
For the first test case,  After changing the next pointer of each node to the previous node, The given linked list is reversed.
Sample Input 2 :
1
10 21 3 2 4 -1
Sample Output 2 :
4 2 3 21 10 -1
Reset Code
Full screen
Auto
copy-code
Console