Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Reorder List

Medium
linked-listtwo-pointers

Given a list L₀ → L₁ → … → Lₙ, reorder it in place to L₀ → Lₙ → L₁ → Lₙ₋₁ → L₂ → … and return the head. Only nodes may be rearranged, not values (though the judge only checks the resulting order).

Input: one line of space-separated integers. Output: the reordered list's values.

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

Constraints

  • 1 ≤ list length ≤ 5·10^4
Watch a video walkthrough

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