Input: [3,9,2,8,1,6,10,5,4,7]

k: 1

Expected output is 6, I can understand that. But what is wrong with 8?

Below is my code

```
public int kEmptySlots(int[] flowers, int k) {
if (flowers == null || flowers.length < k + 2) return -1;
Map<Integer, Integer> map = new HashMap<>(); // <flower, day>
for (int i = 0; i < flowers.length; i++) map.put(flowers[i], i);
for (int i = 1; i < flowers.length - k; i++) {
int max = Math.max(map.get(i), map.get(i + k + 1));
boolean match = true;
for (int j = i + 1; j < i + k + 1; j++) {
if (map.get(j) <= max) {
match = false;
break;
}
}
if (match) return max + 1;
}
return -1;
}
```