Reorder List

Medium
Linked Lists Linked List Two Pointers Stack

Reorder L0→L1→...→Ln to L0→Ln→L1→Ln-1→... Print result.

Constraints

1 ≤ n ≤ 5×10^4

Examples

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
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.