Meandering Array
Updated
Problem statement
You are given an integer array unsorted. Rearrange it in meandering order: take the largest remaining value, then the smallest remaining value, and keep alternating.
The order is [first_largest, first_smallest, second_largest, second_smallest, ...].
Complete meanderingArray(unsorted) and return the rearranged integer array. Keep every input entry, including duplicates.
Function
meanderingArray(unsorted: int[]) → int[]Examples
Example 1
unsorted = [-1, 1, 2, 3, -5]return = [3, -5, 2, -1, 1]The array [-1, 1, 2, 3, -5] sorted normally is [-5, -1, 1, 2, 3]. Sorted in meandering order, it becomes [3, -5, 2, -1, 1].
Constraints
- 2≤n≤10^5
- -10^6 ≤ unsorted[i] ≤ 10^6
- The unsorted array may contain duplicate elements.
More Verisk Online Assessment questions
Similar questions at other companies
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Count Cross-Array Target-Sum PairsVisa · OAVisa interview questions
- Can Every Package Fit in a BoxIMC Trading · OAIMC Trading interview questions
- Minimum Tunnel Crossing TimeArcesium · OAArcesium interview questions
- Merge 2 ArraysIBM · OAIBM interview questions
- Get Maximum PairsAmazon · OA
- Merge 2 ArraysOracle · OAOracle interview questions
- Find Maximum GreatnessTwilio · OATwilio interview questions
- Merge Sorted ArrayAtlassian · OAAtlassian interview questions
- Binge WatchingVanguard · OAVanguard interview questions