#C12104. Maximum Unique Subarray
Maximum Unique Subarray
Maximum Unique Subarray
You are given an array of integers of size \(N\) and an integer \(K\). The task is to determine the maximum number of unique elements in any contiguous subarray of size \(K\).
Formally, for an array \(A[0 \ldots N-1]\), if \(K \le N\) then for each subarray \(A[i], A[i+1], \ldots, A[i+K-1]\) (with \(0 \le i \le N-K\)), let \(U(i)\) denote the number of distinct elements in that subarray. You need to find \(\max_{0 \le i \le N-K} U(i)\). If \(K > N\), output 0.
inputFormat
The input consists of two lines:
- The first line contains two space-separated integers \(N\) and \(K\), where \(N\) is the number of elements in the array and \(K\) is the size of the subarray.
- The second line contains \(N\) space-separated integers representing the array elements.
outputFormat
Output a single integer representing the maximum number of unique elements in any subarray of size \(K\). If \(K > N\), output 0.
## sample6 3
4 1 1 2 3 4
3