#C3983. Longest Distinct Subarray
Longest Distinct Subarray
Longest Distinct Subarray
Given an array of integers with length n, find the length of the longest contiguous subarray in which all elements are distinct. The first input line contains two integers n and k (k is not used in the algorithm but provided as input) and the next line contains n integers representing the array.
In other words, you are to determine the maximum size of a window in the array that does not contain any repeated element.
Formally, let (a_1, a_2, \dots, a_n) be the sequence of integers, then find the maximum (L) such that there exists an index (i) for which the subarray (a_i, a_{i+1}, \dots, a_{i+L-1}) has all distinct elements.
inputFormat
The input is given via standard input (stdin) and consists of two lines.
The first line contains two integers (n) and (k) (where (n) is the size of the array and (k) is a dummy parameter).
The second line contains (n) space-separated integers representing the array elements.
outputFormat
Output a single integer via standard output (stdout): the length of the longest contiguous subarray that contains all distinct elements.## sample
8 4
2 1 4 3 1 2 2 3
4