Reorder List
Problem Statement
Given the head of a singly linked list, reorder it such that the nodes in the list are arranged in an alternating left-to-right and right-to-left manner, while keeping the original relative order of the nodes.
Rules and Constraints
- The linked list should be non-empty.
- The linked list nodes are singly linked (i.e., each node contains a pointer to the next node, but not to the previous one).
- The reordering should be done in-place, without creating any additional nodes or modifying the original linked list structure.
Input/Output
The input to the problem is the head of a singly linked list, and the output is the modified linked list with the nodes reordered according to the problem statement.
Example
Input: {"head":[1,2,3,4]} Output: [1,4,2,3]
CompaniesMeta
JavaScript
Login to write code
Solve problems, verify your skills, and earn XP.