Company: Citi_12oct
Difficulty: medium
Longest Switching Slice Problem Description Call an array switching when every element in an even position holds the same value and every element in an odd position holds the same value. Positions are counted from 0 at the first element of the array being checked. The even value and the odd value may be equal or different. For instance, [3, -7, 3, -7, 3] and [4, 4, 4] are switching. [5, 5, 4, 5, 4] is not (its even positions hold 5, 4, 4 ), and neither is [-3, 2, 3] (its even positions hold -3 and 3 ). A slice of A is a block of consecutive elements A[i], A[i+1], ..., A[j] with i <= j . Given an array A of N integers, find the length of its longest slice that is switching. Write a function solution(A) that returns that length. Input Format The first line contains an integer N , the number of elements. The second line contains N space-separated integers A[0], A[1], ..., A[N-1] . Output Format Print a single integer: the length of the longest switching slice of A . Constraints 1 <=