#K58112. Shortest Nice Segment
Shortest Nice Segment
Shortest Nice Segment
Given an array of integers, a segment (subarray) is called nice if it contains at least one occurrence of every integer from 1 to M (inclusive). In other words, the segment is nice if it contains all the integers in the set \(\{1, 2, \ldots, M\}\).
You are given T test cases. For each test case, you are provided with two integers N and M where N is the length of the array and M is the maximum integer that must be included in the nice segment. You are also given an array of N integers. Your task is to determine the length of the shortest nice segment. If no such segment exists, output -1
.
Example:
Input: 1 5 2 1 2 1 2 1</p>Output: 2
inputFormat
The first line of the input contains an integer T denoting the number of test cases. For each test case, the first line contains two integers N and M separated by a space. The second line contains N integers representing the elements of the array.
Note: Input is read from standard input (stdin).
outputFormat
For each test case, output a single line with one integer: the length of the shortest nice segment. If there is no nice segment, output -1
.
Note: Output should be printed to standard output (stdout).
## sample1
5 2
1 2 1 2 1
2
</p>