Find Good Days to Rob the Bank LeetCode solution in C++
1class Solution {2public:3vector<int> goodDaysToRobBank(vector<int> &security, int time) {4int n = security.size();5vector<int> prefix(n), suffix(n);6vector<int> ans;78prefix[0] = 0;9for (int i = 1; i < n; i++) {10if (security[i] <= security[i - 1])11prefix[i] = prefix[i - 1] + 1;12else13prefix[i] = 0;14}1516suffix[n - 1] = 0;17for (int i = (n - 2); i >= 0; i--) {18if (security[i] <= security[i + 1])19suffix[i] = suffix[i + 1] + 1;20else21suffix[i] = 0;22}2324for (int i = 0; i < n; i++) {25if (prefix[i] >= time && suffix[i] >= time) ans.push_back(i);26}2728return ans;29}30};