FastPrepMeandering Array
Problems/Meandering Array

Meandering Array

IBM logoIBM● EasyOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem 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:

  1. 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

  • 2≤n≤10^5
  • -10^6 ≤ unsorted[i] ≤ 10^6
  • The unsorted array may contain duplicate elements.

More IBM interview questions

  • Missing IntervalsOA · Seen Nov 2026
  • Count Peaks and ValleysOA · Seen Nov 2026
  • Last Object Exit TimeOA · Seen Nov 2026
  • Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
  • Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
  • Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
  • Alternate Odd and Even Numbers with Two GoroutinesPHONE SCREEN · Seen Nov 2026
  • Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Nov 2026
  • Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
  • Longest Palindromic SubstringPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Meandering ArrayVerisk · OA
  • 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
  • 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

IBM interview experiences

  • IBM Full-Time SWE OA Questions: 1 Experience
  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public int[] meanderingArray(int[] unsorted) {
      // write your code here
    }

}
Checking account…