Longest Switching Subarray Problem Statement
You are given an array ‘ARR’ containing ‘N’ positive integers. Your objective is to find the length of the longest contiguous subarray that exhibits switching behavior.
A subarray is described as switching if all elements at even indices are equal and all elements at odd indices are equal.
Input:
The input starts with an integer T, indicating the number of test cases.
Each test case is as follows:
The first line contains an integer 'N', the length of the array.
The second line contains N space-separated positive integers representing the array elements.
Output:
For each test case, output a single integer representing the length of the longest switching subarray.
Example:
Input:
1
8
1 4 1 4 3 2 3 0
Output:
4
Explanation: Some examples of switching subarrays are {1, 4, 1, 4}, {3, 2, 3}. The longest among these is {1, 4, 1, 4}, resulting in an output length of 4.
Constraints:
- 1 <= T <= 10
- 1 <= N <= 105
- 1 <= ARR[i] <= 108
Note:
There is no need for printing; the function should return the expected output for each test case.

Find the length of the longest contiguous subarray where elements at even indices are equal and elements at odd indices are equal.
Iterate through the array and keep track of the length of the current ...read more
TCS Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in TCS Software Developer


Reviews
Interviews
Salaries
Users

