Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Reorder List

XPChallenge Points: 20
levelLevel: Medium

You are given a singly linked list. Rearrange it in a new order:
First node → Last node → Second node → Second last node → Third node → …
You cannot change the node values; only the node links can be changed.

Example 1:

Input: head = [10,20,30,40]

Output: [10,40,20,30]

Explanation:

Rearrange as first → last → second → second last.

Example 2:

Input: head = [1,2,3,4,5]

Output: [1,5,2,4,3]

Example 3:

Input: head = [7,8,9]

Output: [7,9,8]

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result