#K52977. Distinct Subarray Check

    ID: 29429 Type: Default 1000ms 256MiB

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:

  1. The first line contains an integer n, representing the size of the array.
  2. The second line contains n space-separated integers representing the elements of the array.
  3. 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.

## sample
7
1 2 3 4 3 2 1
4
Yes