Ninja and Alternating Largest Problem Statement
Ninja is given a sequence of numbers and needs to rearrange them so that every second element is greater than its neighbors on both sides.
Example:
Input:
[1, 2, 3, 4, 5]
Output:
[1, 3, 2, 5, 4]
Explanation:
The given array [1, 2, 3, 4, 5] is rearranged to [1, 3, 2, 5, 4] where every second element is greater than its left and right element.
Constraints:
1 <= T <= 10
1 <= N <= 10^4
0 <= array[i] <= 10^5
- Time limit: 1 sec
Input:
The first line of input contains an integer T, the number of test cases.
The first line of each test case contains an integer N, the number of elements in the array.
The second line of each test case contains the array elements.
Output:
For each test case, output 1 if the array can be rearranged to meet the conditions, otherwise output 0.
Note:
If the array returned satisfies the given conditions, the output will be 1; otherwise, it will be 0. Implementation should handle the output internally.

AnswerBot
1y
The task is to rearrange the given array such that every second element is greater than its left and right element.
Read the number of test cases
For each test case, read the number of elements in the a...read more
Help your peers!
Add answer anonymously...
ZeMoSo Technologies Associate Software Engineer interview questions & answers
An Associate Software Engineer was asked 8mo agoQ. Write a program to check whether the parentheses are properly balanced, meaning ...read more
An Associate Software Engineer was asked 8mo agoQ. Given a Map of fruits with their price as a key-value pair respectively, find th...read more
An Associate Software Engineer was asked 8mo agoQ. Given a list of integers, find the first non-repeating integer using the Stream ...read more
Popular interview questions of Associate Software Engineer
An Associate Software Engineer was asked 9mo agoQ1. Write a program to check whether the parentheses are properly balanced, meaning ...read more
An Associate Software Engineer was asked 9mo agoQ2. Given a Map of fruits with their price as a key-value pair respectively, find th...read more
An Associate Software Engineer was asked 9mo agoQ3. Given a list of integers, find the first non-repeating integer using the Stream ...read more
>
ZeMoSo Technologies Associate Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

