Tap here to switch tabs
Problem
Submissions

Problem: Find All Good Indices

med
30 min
Try to solve the Find All Good Indices problem.

Statement

You are given a 00 indexed integer array nums of length n and an positive integer k.

An index i is considered a good index if it satisfies the following conditions:

  • k ≤\le i << n −- k

  • The k elements immediately preceding index i are in non increasing order: nums[i - k] ≥\ge nums[i - k + 1] ≥⋯≥\ge \dots \ge nums[i - 1]

  • The k elements immediately following index i are in non decreasing order: nums[i + 1] ≤\le nums[i + 2] ≤⋯≤\le \dots \le nums[i + k]

Return a list of all good indices sorted in increasing order.

Constraints:

  • n == nums.length

  • 3≤3 \le n ≤105\le 10^5

  • 1≤1 \le nums[i] ≤106\le 10^6

  • 1≤1 \le k ≤\le n /2/ 2

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find All Good Indices

med
30 min
Try to solve the Find All Good Indices problem.

Statement

You are given a 00 indexed integer array nums of length n and an positive integer k.

An index i is considered a good index if it satisfies the following conditions:

  • k ≤\le i << n −- k

  • The k elements immediately preceding index i are in non increasing order: nums[i - k] ≥\ge nums[i - k + 1] ≥⋯≥\ge \dots \ge nums[i - 1]

  • The k elements immediately following index i are in non decreasing order: nums[i + 1] ≤\le nums[i + 2] ≤⋯≤\le \dots \le nums[i + k]

Return a list of all good indices sorted in increasing order.

Constraints:

  • n == nums.length

  • 3≤3 \le n ≤105\le 10^5

  • 1≤1 \le nums[i] ≤106\le 10^6

  • 1≤1 \le k ≤\le n /2/ 2