CodeScoop.dev

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

Online JS Compiler

Output: