visitors[i] is how many guests are expected on day i (days are 0-based). You are also given a number span.
Day i works if:
- there are at least span days both before and after it;
- over the span days leading up to day i, attendance never goes up: visitors[i - span] ≥ … ≥ visitors[i];
- over the span days after it, attendance never goes down: visitors[i] ≤ … ≤ visitors[i + span].
Return all such days in ascending order.visitors=[9, 7, 7, 4, 6, 8, 3], span=2 → [3]
Day 3: before it 7 ≥ 7 ≥ 4, after it 4 ≤ 6 ≤ 8. No other day works.
visitors=[5, 5, 5], span=1 → [1]
The numbers never change, so the only day with a neighbour on each side qualifies.
visitors=[3, 1, 2], span=0 → [0, 1, 2]
With span = 0 every day qualifies.
visitors=[9, 7, 7, 4, 6, 8, 3], span=2
[3]
Run checks the first 3 tests in your browser. Submit checks all 126 tests on the server, hidden ones included.