410. Reorder List to Min-Max Interleaving

HardLinked ListSortingTwo PointersLinked List

Given a linked list, reorder it so the values follow a min-max interleaving: smallest, largest, second smallest, second largest, and so on. This is achieved by sorting the values and then alternately taking from the front and back. Return the resulting list as an array.

Input: An array of node values.

Output: Array — the min-max interleaved list.

Examples

Example 1
Input: [1,2,3,4,5,6]
Output: [1,6,2,5,3,4]
Explanation: Alternate smallest and largest.
Example 2
Input: [5,4,3,2,1]
Output: [1,5,2,4,3]
Explanation: Sorted then interleaved.
Example 3
Input: [1]
Output: [1]
Explanation: Single node.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →