You are given an integer array A containing N integers.
You can remove atmost one subarray from it such that the remaining elements must occur atmost two times.
Find the minimum size of the subarray you need to remove such that remaining elements must occur for atmost two times.
1 <= N <= 105
1 <= A[i] <= 109
First and only argument is an integer array A.
Return an integer denoting the minimum size of the subarray you need to remove such that remaining elements must occur for atmost two times.
A = [1, 1, 1, 2, 2, 2]
A = [1, 1, 2, 2]
If we remove the subarray A[2:3] then A = [1, 1, 2, 2] and as you can see count of 1 is atmost 2 and count of 2 is atmost 2 so this will be our optimal answer so length of subrray which needs to be removed = 2
Initially each elements occurs for atmost two times so we do not need to remove any subarray. Hence we will return 0
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a question? Checkout Sample Codes for more details.