less than 1 minute read

Given a singly linked list node, reorder it such that we take: the last node, and then the first node, and then the second last node, and then the second node, etc.

Can you do it in \(\mathcal{O}(1)\) space?

Constraints

  • 0 ≤ n ≤ 100,000 where n is the number of nodes in node

https://binarysearch.com/problems/Back-to-Front-Linked-List

Examples

Example 1

Input

  • node =

Output

  • answer =

Solution

Leave a comment