To solve this problem, you'll have to open it on the computer

Reverse Linked List

Linked list
easy
Score: 20

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

Class Node:
    data (int)
    next (Node)

Input Format

First Parameter - Node head

Output Format

Return the Node

Example 1:

Input: 1 2 3 4 5 6 7 8 

Output: 8 7 6 5 4 3 2 1

Example 2:

Input: 1 5 6

Output: 6 5 1

Constraints:

  • 1 <= N <= 10^4
  • -5000 <= Node.data <= 5000
  • Expected Time Complexity: O(N)
  • Expected Space Complexity: O(1)
Submit code to see the your result here