2100. Find Good Days to Rob the Bank Medium

@problem@discussion
#Array#Dynamic Programming#Prefix Sum



1/**
2 * [2100] Find Good Days to Rob the Bank
3 *
4 * 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.
5 * The i^th day is a good day to rob the bank if:
6 * 
7 * 	There are at least time days before and after the i^th day,
8 * 	The number of guards at the bank for the time days before i are non-increasing, and
9 * 	The number of guards at the bank for the time days after i are non-decreasing.
10 * 
11 * 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].
12 * 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.
13 *  
14 * Example 1:
15 * 
16 * Input: security = [5,3,3,3,5,6,2], time = 2
17 * Output: [2,3]
18 * Explanation:
19 * On day 2, we have security[0] >= security[1] >= security[2] <= security[3] <= security[4].
20 * On day 3, we have security[1] >= security[2] >= security[3] <= security[4] <= security[5].
21 * No other days satisfy this condition, so days 2 and 3 are the only good days to rob the bank.
22 * 
23 * Example 2:
24 * 
25 * Input: security = [1,1,1,1,1], time = 0
26 * Output: [0,1,2,3,4]
27 * Explanation:
28 * Since time equals 0, every day is a good day to rob the bank, so return every day.
29 * 
30 * Example 3:
31 * 
32 * Input: security = [1,2,3,4,5,6], time = 2
33 * Output: []
34 * Explanation:
35 * No day has 2 days before it that have a non-increasing number of guards.
36 * Thus, no day is a good day to rob the bank, so return an empty list.
37 * 
38 *  
39 * Constraints:
40 * 
41 * 	1 <= security.length <= 10^5
42 * 	0 <= security[i], time <= 10^5
43 * 
44 */
45pub struct Solution {}
46
47// problem: https://leetcode.com/problems/find-good-days-to-rob-the-bank/
48// discuss: https://leetcode.com/problems/find-good-days-to-rob-the-bank/discuss/?currentPage=1&orderBy=most_votes&query=
49
50// submission codes start here
51
52impl Solution {
53    pub fn good_days_to_rob_bank(security: Vec<i32>, time: i32) -> Vec<i32> {
54        vec![]
55    }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63
64    #[test]
65    fn test_2100() {
66    }
67}
68


Back
© 2025 bowen.ge All Rights Reserved.