#K72117. Longest Subarray with K Distinct Elements
Longest Subarray with K Distinct Elements
Longest Subarray with K Distinct Elements
Given an array of integers and an integer \( k \), find the length of the longest continuous subarray that contains at most \( k \) distinct elements. In other words, you need to determine the maximum size of a contiguous segment of the array such that the number of distinct elements does not exceed \( k \).
Note: If \( k = 0 \), the result should be 0.
The input format is detailed below. Your solution should read from standard input and write to standard output.
inputFormat
The first line contains two integers \( n \) and \( k \) where \( n \) is the number of elements in the array and \( k \) is the maximum number of distinct elements allowed in the subarray.
The second line contains \( n \) space-separated integers representing the array elements.
outputFormat
Output a single integer that represents the length of the longest continuous subarray with at most \( k \) distinct elements.
## sample7 2
1 2 1 3 4 2 3
3