#C473. Maximum Distinct Elements in Subarrays
Maximum Distinct Elements in Subarrays
Maximum Distinct Elements in Subarrays
You are given an integer array \(A\) of length \(n\) and a positive integer \(k\). Your task is to determine the maximum number of distinct elements in any contiguous subarray of \(A\) of length \(k\).
Note: A subarray is a contiguous part of an array. For example, if \(A = [4, 3, 1, 1, 2, 3, 3]\) and \(k = 4\), then one possible subarray is \([3, 1, 1, 2]\) which contains 3 distinct elements.
Input Format: The input is read from standard input (stdin). The first line contains two integers \(n\) and \(k\) separated by a space. The second line contains \(n\) integers separated by spaces.
Output Format: Print the maximum number of distinct elements found in any subarray of length \(k\) to standard output (stdout).
Constraints:
- \(1 \leq k \leq n \leq 10^5\)
- \(A[i]\) can be any integer.
Example:
Input: 7 4 4 3 1 1 2 3 3</p>Output: 3
inputFormat
The first line of input contains two integers \(n\) and \(k\), where \(n\) is the number of elements in the array, and \(k\) is the length of the subarray. The second line contains \(n\) space-separated integers representing the elements of the array.
outputFormat
Print a single integer which is the maximum number of distinct elements in any subarray of length \(k\>.
## sample7 4
4 3 1 1 2 3 3
3