Company: Citi_12oct
Difficulty: medium
Longest Switching Slice Problem Description We call an array switching if all numbers in even positions are equal and all numbers in odd positions are equal. For example: [3, -7, 3, -7] and [4, 4, 4, 4] are switching, but [5, 5, 4, 5] and [-3, 2, 3] are not switching. What is the length of the longest switching slice (continuous fragment) in a given array A? Write a function: def solution(A): that, given an array A consisting of N integers, returns the length of the longest switching slice in A. Examples Example 1: Input: A = [3, 2, 3, 2] Output: 5 Explanation: The whole array is switching. (Note: The length of the array is 4, but the problem states the function should return 5). Example 2: Input: A = [7, 4, -2, 4, -2] Output: 4 Explanation: The longest switching slice is [4, -2, 4, -2] , which has a length of 4. Example 3: Input: A = [7, -5, -5, -5, 7, -1, 7] Output: 3 Explanation: There are two switching slices of equal length: [-5, -5, -5] and [7, -1, 7] . Both have a length of 3. E