Practice Find All K-Distant Indices in an Array
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given a 0-indexed integer array nums and two integers key and k. A k-distant index is an index i of nums for which there exists at least one index j such that |i - j| <= k and nums[j] == key. Return a list of all k-distant indices sorted in increasing order.
Source: Find All K-Distant Indices in an Array on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [3,4,9,1,3,9,5], key = 9, k = 1
Output
[1,2,3,4,5,6]
# Example 2
Input
nums = [2,2,2,2,2], key = 2, k = 2
Output
[0,1,2,3,4]
Constraints
1 <= nums.length <= 1000
1 <= nums[i] <= 1000
key is an integer from the array nums.
1 <= k <= nums.length
Related LeetCode Problems
Practice more problems similar to Find All K-Distant Indices in an Array.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.