#K52977. Distinct Subarray Check
Distinct Subarray Check
Distinct Subarray Check
Given an array of integers and an integer k, determine whether there exists a consecutive subarray of length k that contains all distinct integers from 1 to k exactly once. In other words, for a subarray S of length k, we require that
\( S = \{1, 2, \dots, k\} \)
If such a subarray exists, output Yes; otherwise, output No.
inputFormat
The input is given via stdin in the following format:
- The first line contains an integer n, representing the size of the array.
- The second line contains n space-separated integers representing the elements of the array.
- The third line contains an integer k.
outputFormat
Output a single line to stdout containing Yes if there exists any consecutive subarray of length k that equals the set \(\{1, 2, \dots, k\}\). Otherwise, output No.
## sample7
1 2 3 4 3 2 1
4
Yes