Problem · Array
Meandering Array
Learn this problemProblem statement
An array of integers is defined as being in meandering order when the first two elements are the respective largest and smallest elements in the array and the subsequent elements alternate between its next largest and next smallest elements. In other words, the elements are in order of [first_largest, first_smallest, second_largest, second_smallest, ...].
Function
meanderingArray(unsorted: int[]) → int[]
Complete the function meanderingArray in the editor below.
meanderingArray has the following parameters:
int unsorted[n]: the unsorted array
Returns
int[n]: the array sorted in meandering order
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
More IBM problems
- Parent Process NumberOA · Seen Jul 2026
- Request Retry CountOA · Seen Jul 2026
- Count Strictly Increasing Subsequences of Length 3OA · Seen Jul 2026
- Maximum Requests in a Time WindowOA · Seen Jul 2026
- Query Type Frequency WindowOA · Seen Jul 2026
- Minimum Number of Non-Empty Disjoint SegmentsOA · Seen Jul 2026
- Spam Text ClassificationOA · Seen Jul 2026
- Count Ideal NumbersOA · Seen Jun 2026