Ninja And Alternating Largest
Ninja is given a few numbers, and he is being asked to rearrange the numbers so that every second element is greater than its left and right element.
Input Format:
The first line of input contains a single integer T, representing the number of test cases.
The first line of each test case contains ‘N’, denoting the number of elements in the array.
The second line of each test case contains the array elements.
Output Format :
The first and only line of each test case in the output contains the rearranged array.
Note:
You are not required to print the expected output; it has already been taken care of. Just implement the function.
Constraints:
1 <= T <= 10
1 <= N <= 10^5
0 <= array[i] <= 10^5
Time limit: 1 second
CodingNinjas
author
2y
Brute forceSpace Complexity: O(1)Explanation: Time Complexity: O(n)Explanation:
Help your peers!
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