Find Good Days to Rob the Bank

You and a gang of thieves are planning on robbing a bank. You are given a 0-indexed integer array security, where security[i] is the number of guards on duty on the i^th day. The days are numbered starting from 0. You are also given an integer time.

The i^th day is a good day to rob the bank if:

  • There are at least time days before and after the i^th day.
  • The number of guards at the bank for the time days before i are non-increasing.
  • The number of guards at the bank for the time days after i are non-decreasing.

More formally, this means day i is a good day to rob the bank if and only if security[i - time] >= security[i - time + 1] >= ... >= security[i] <= ... <= security[i + time - 1] <= security[i + time].

Return a list of all days (0-indexed) that are good days to rob the bank. The order that the days are returned in does not matter.

Example 1
Inputsecurity = [5,3,3,3,5,6,2], time = 2
Output[2,3]
On days 2 and 3, the required guard counts before are non-increasing and the required guard counts after are non-decreasing, and no other days satisfy the condition.
Example 2
Inputsecurity = [1,1,1,1,1], time = 0
Output[0,1,2,3,4]
Since time equals 0, every day is a good day to rob the bank, so return every day.

Constraints

  • 1 <= security.length <= 10^5
  • 0 <= security[i], time <= 10^5

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate