#C3793. Maximum Distinct Elements in a Subarray
Maximum Distinct Elements in a Subarray
Maximum Distinct Elements in a Subarray
You are given an array \(A\) of \(N\) integers and an integer \(K\). Your task is to find the maximum number of distinct integers among all contiguous subarrays of size \(K\).
A subarray is a contiguous segment of the array. Formally, for an array \(A = [a_1, a_2, \dots, a_N]\), a contiguous subarray of length \(K\) is defined as \([a_i, a_{i+1}, \dots, a_{i+K-1}]\) for \(1 \leq i \leq N-K+1\).
The goal is to determine the maximum distinct element count across all such subarrays.
Constraints:
- \(1 \leq K \leq N\)
- \(N\) is the number of elements in the array \(A\).
inputFormat
The input is given via standard input (stdin) and has the following format:
N K A[0] A[1] ... A[N-1]
Where:
- \(N\) is the number of elements in the array.
- \(K\) is the size of the subarray.
- The second line contains \(N\) space-separated integers representing the array \(A\).
outputFormat
Output a single integer to standard output (stdout) which is the maximum number of distinct integers among all contiguous subarrays of size \(K\).
## sample7 3
4 1 1 3 1 4 2
3