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 ith day. The days are numbered starting from 0. You are also given an integer time.

The ith day is a good day to rob the bank if:


	There are at least time days before and after the ith day,
	The number of guards at the bank for the time days before i are non-increasing, and
	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] &gt;= security[i - time + 1] &gt;= ... &gt;= security[i] &lt;= ... &lt;= security[i + time - 1] &lt;= 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.

&nbsp;
Example 1:

Input: security = [5,3,3,3,5,6,2], time = 2
Output: [2,3]
Explanation:
On day 2, we have security[0] &gt;= security[1] &gt;= security[2] &lt;= security[3] &lt;= security[4].
On day 3, we have security[1] &gt;= security[2] &gt;= security[3] &lt;= security[4] &lt;= security[5].
No other days satisfy this condition, so days 2 and 3 are the only good days to rob the bank.


Example 2:

Input: security = [1,1,1,1,1], time = 0
Output: [0,1,2,3,4]
Explanation:
Since time equals 0, every day is a good day to rob the bank, so return every day.


Example 3:

Input: security = [1,2,3,4,5,6], time = 2
Output: []
Explanation:
No day has 2 days before it that have a non-increasing number of guards.
Thus, no day is a good day to rob the bank, so return an empty list.


&nbsp;
Constraints:


	1 &lt;= security.length &lt;= 105
	0 &lt;= security[i], time &lt;= 105


class Solution:
    def goodDaysToRobBank(self, security: List[int], time: int) -> List[int]:
        decreasing = [0] * len(security)
        increasing = [0] * len(security)
        for i in range(len(security)):
            if i > 0 and security[i - 1] >= security[i]:
                decreasing[i] = decreasing[i - 1] + 1
        for i in reversed(range(len(security))):
            if i < len(security) - 1 and security[i] <= security[i + 1]:
                increasing[i] = increasing[i + 1] + 1
        return [i for i in range(len(security)) if increasing[i] >= time and decreasing[i] >= time]
class Solution {
    public List<Integer> goodDaysToRobBank(int[] security, int time) {
        List<Integer> res = new ArrayList<>();
        if (time == 0) {
            for (int i = 0; i < security.length; i++) res.add(i);
            return res;
        }
        Set<Integer> set = new HashSet<>();
        int count = 1;
        for (int i = 1; i < security.length; i++) {
            if (security[i] <= security[i - 1]) {
                count++;
            } else {
                count = 1;
            }
            if (count > time) {
                set.add(i);
            }
        }
        
        count = 1;
        for (int i = security.length - 2; i >= 0; i--) {
            if (security[i] <= security[i + 1]) {
                count++;
            } else {
                count = 1;
            }
            if (count > time && set.contains(i)) res.add(i);
        }
        return res;
    }
}
class Solution {
public:
    vector<int> goodDaysToRobBank(vector<int>& security, int time) {
        int n = security.size();
        vector<int> prefix(n), suffix(n);
        vector<int> ans;
        
        prefix[0] = 0;
        for(int i=1;i<n;i++) {
            if(security[i] <= security[i-1]) prefix[i] = prefix[i-1]+1;
            else prefix[i] = 0;
        }
        
        suffix[n-1] = 0;
        for(int i=(n-2);i>=0;i--) {
            if(security[i] <= security[i+1]) suffix[i] = suffix[i+1]+1;
            else suffix[i] = 0;
        }
        
        for(int i=0;i<n;i++) {
            if(prefix[i]>=time && suffix[i]>=time) ans.push_back(i);
        }
        
        return ans;
    }
};
var goodDaysToRobBank = function(security, time) {
    let res = [];
    if(!time){
       let i = 0;
        while(i<security.length) res.push(i), i++;
        return res;
    }
    let increasing = 0;
    let decreasing = 0;
    let set = new Set();
    for(let i = 1; i < security.length; i++){
        if(security[i]>security[i-1]) decreasing = 0;
        else decreasing++;
        if(security[i]<security[i-1]) increasing = 0;
        else increasing++;
        if(decreasing>=time) set.add(i);
        if(increasing>=time&&set.has(i-time)) res.push(i-time);
    }
    return res;
};
Find Good Days to Rob the Bank