2420. Find All Good Indices Medium
1/**
2 * [2420] Find All Good Indices
3 *
4 * You are given a 0-indexed integer array nums of size n and a positive integer k.
5 * We call an index i in the range k <= i < n - k good if the following conditions are satisfied:
6 *
7 * The k elements that are just before the index i are in non-increasing order.
8 * The k elements that are just after the index i are in non-decreasing order.
9 *
10 * Return an array of all good indices sorted in increasing order.
11 *
12 * Example 1:
13 *
14 * Input: nums = [2,1,1,1,3,4,1], k = 2
15 * Output: [2,3]
16 * Explanation: There are two good indices in the array:
17 * - Index 2. The subarray [2,1] is in non-increasing order, and the subarray [1,3] is in non-decreasing order.
18 * - Index 3. The subarray [1,1] is in non-increasing order, and the subarray [3,4] is in non-decreasing order.
19 * Note that the index 4 is not good because [4,1] is not non-decreasing.
20 * Example 2:
21 *
22 * Input: nums = [2,1,1,2], k = 2
23 * Output: []
24 * Explanation: There are no good indices in this array.
25 *
26 *
27 * Constraints:
28 *
29 * n == nums.length
30 * 3 <= n <= 10^5
31 * 1 <= nums[i] <= 10^6
32 * 1 <= k <= n / 2
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/find-all-good-indices/
38// discuss: https://leetcode.com/problems/find-all-good-indices/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn good_indices(nums: Vec<i32>, k: i32) -> Vec<i32> {
44 vec![]
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_2420() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.