K Empty Slots
There is a garden withN
slots. In each slot, there is a flower. TheN
flowers will bloom one by one inN
days. In each day, there will beexactly
one flower blooming and it will be in the status of blooming since then.
Given an arrayflowers
consists of number from1
toN
. Each number in the array represents the place where the flower will open in that day.
For example,flowers[i] = x
means that the unique flower that blooms at dayi
will be at positionx
, wherei
andx
will be in the range from1
toN
.
Also given an integerk
, you need to output in which day there exists two flowers in the status of blooming, and also the number of flowers between them isk
and these flowers are not blooming.
If there isn't such day, output -1.
Example 1:
Example 2:
Note:
The given array will be in the range [1, 20000].
Solution
Last updated