Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Reverse Linked List

Easy
linked-listrecursion

Given the head of a singly linked list, reverse it and return the new head.

Input: one line of space-separated integers — the list values in order (may be empty). Output: the reversed list's values, space-separated.

Example 1
Input:
1 2 3 4 5
Output:
5 4 3 2 1
Example 2
Input:
1 2
Output:
2 1
Example 3
Input:
Output:

Constraints

  • 0 ≤ list length ≤ 5000
  • -5000 ≤ node values ≤ 5000
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.