BackeasyMath

Invert Node Connections Solution

Problem Statement

Reverse a singly linked list in-place, so each node points to the previous node instead of the next one. The first node should point to none, and the last node should correctly point to what was previously the first node.

Example 1
Input
[5, 11, 8, 2, 15]
Output
[5,11,8,2,15]
Example 2
Input
[7, 4]
Output
[7,4]

Constraints

  • The input sequence will contain at least one node.
  • Each node in the sequence has a unique value.
  • The sequence will not be empty.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free