if len(trees) == K:
    if first_index == -1 or alley[first_index] == alley[i]:
        first_index = min(trees.values())
idx = first_index + 1, i + 1
length = idx[1] - idx[0] + 1
if length < min_length:
    min_idx = idx
min_length = length
if min_length == K:
    break
find minimum-length subarray that has all numbers