Tap here to switch tabs
Problem
Submissions

Problem: Find All K-Distant Indices in an Array

med
30 min
Try to solve the Find All K-Distant Indices in an Array problem.

Statement

Given a 00 indexed integer array nums and two integers key and k, an index i is considered a kk distant index if there exists at least one index j such that ∣i−j∣≤|i - j| \leq k and nums[j] is equal to key.

Return a list of all kk distant indices sorted in ascending order.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤1000\leq 1000

  • key is an integer present in the array nums

  • 1≤1 \leq k ≤\leq nums.length

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find All K-Distant Indices in an Array

med
30 min
Try to solve the Find All K-Distant Indices in an Array problem.

Statement

Given a 00 indexed integer array nums and two integers key and k, an index i is considered a kk distant index if there exists at least one index j such that ∣i−j∣≤|i - j| \leq k and nums[j] is equal to key.

Return a list of all kk distant indices sorted in ascending order.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤1000\leq 1000

  • key is an integer present in the array nums

  • 1≤1 \leq k ≤\leq nums.length