Find Good Days to Rob the Bank
specialist · 850 · lc medium +31 · verified · 51.4% accepted · 1,000 likes · top 40%
Description
You and a gang of thieves are planning to rob a bank. You are given a 0-indexed integer array security, where security[i] is the number of guards on duty on the ith day. The days are numbered starting from 0. You are also given an integer time.
Day i is considered a good day to rob the bank when all of the following hold:
- There are at least time days both before and after day i,
- The guard counts for the time days preceding day i are non-increasing, and
- The guard counts for the time days following day i are non-decreasing.
Formally, day i is good 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 good days (0-indexed). The order in which the days are returned does not matter.
Example 1:
Example 2:
Example 3:
Code