Longest Switching Subarray Problem Statement
Determine the length of the longest contiguous subarray in a given array of positive integers, where the subarray qualifies as 'switching'. An array is defined as switching if all numbers in even positions are identical and all numbers in odd positions are identical.
Example:
Input:
ARR = [1, 4, 1, 4, 3, 2, 3, 0]
Output:
4
Explanation:
The subarray [1, 4, 1, 4]
is switching and has length 4, which is the longest.
Input:
The first line contains an integerT
, the number of test cases. Each test case consists of:
- An integerN
, the size of the array.
- An arrayARR
ofN
positive integers.
Output:
For each test case, output the length of the longest switching subarray.
Constraints:
1 <= T <= 10
1 <= N <= 10^5
1 <= ARR[i] <= 10^8
Note:
No need for explicit printing. Implement the function to return the result.
Be the first one to answer
Add answer anonymously...
Top American Express Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
>
American Express Software Developer Intern 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