Alternating Largest Problem Statement
Given a list of numbers, rearrange them such that every second element is greater than its adjacent elements. Implement a function to achieve this rearrangement.
Input:
The first line contains an integer T, indicating the number of test cases.
Each test case consists of a line with integer N, representing the number of elements.
The next line contains N integers describing the array.
Output:
For each test case, output the rearranged array on a single line.
Example:
Input:
1
5
3 1 2 5 4
Output:
1 3 2 5 4
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 10^5
0 ≤ array[i] ≤ 10^5
- Time limit: 1 second
Note:
No need to handle printing of the results; focus only on implementing the solution.
Be the first one to answer
Add answer anonymously...
Top Microsoft Corporation Full Stack Developer interview questions & answers
Popular interview questions of Full Stack Developer
Top HR questions asked in Microsoft Corporation Full Stack Developer
>
Microsoft Corporation Full Stack Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app