Reverse a Linked List
Difficulty: Beginner
Write a function to reverse a singly linked list. Implement both iterative and recursive approaches.
Example:
Input: 1 → 2 → 3 → 4 Output: 4 → 3 → 2 → 1
You have not submitted this problem yet.
Recursive Solution:
function reverse(head) {
if (!head || !head.next) return head;
let newHead = reverse(head.next);
head.next.next = head;
head.next = null;
return newHead;
}