Similar Problems
Similar Problems not available
Printing a linked list in reverse - Leetcode Solution
LeetCode: Printing a linked list in reverse Leetcode Solution
Difficulty: Unknown
Topics: linked-list
Given a singly linked list, print the elements of the linked list in reverse without modifying the linked list
Example Test Cases
Sample Test Case 1
Input Array: [1 -> 2 -> 3]
Expected Output: 3, 2, 1
Solution
We can solve this problem easily by using recursion. The idea is to print the value of a node only after it’s subsequent’s node’s value is printed. If there are no subsequent nodes then print the value directly as shown in the code below.
Printing a linked list in reverse Solution Code
1