top of page

Looking to master object-oriented and system design for tech interviews or career growth?

  • Improve your system design and machine coding skills.

  • Study with our helpful resources.

  • Prepare for technical interviews and advance your career.

**We're in beta mode and would love to hear your feedback.

Writer's pictureilluminati

Wave Array Interviewbit Solution

Problem: Wave Array


Problem Description:

Given an array of integers, sort the array into a wave like array and return it, In other words, arrange the elements into a sequence such that

a1 >= a2 <= a3 >= a4 <= a5.....

Example

Given [1, 2, 3, 4]  
One possible answer : [2, 1, 4, 3] 
Another possible answer : [4, 1, 3, 2] 

NOTE : If there are multiple answers possible, return the one that's lexicographically smallest. So, in the example case, you will return [2, 1, 4, 3]

Solution:


Comments


bottom of page