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 integer T, the number of test cases. Each test case consists of:
- An integer N, the size of the array.
- An array ARR of N 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...
American Express Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter