Trains the technique from
LeetCode 2200Find All K-Distant Indices in an ArrayThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A row of readings is given, together with a value key that turns up somewhere in the row and a whole number k.
A position i is near when the row holds key at some position j with the gap between i and j no more than k.
Return every near position, in increasing order.
Example 1
The value sits at each end of the row, so both ends and their single neighbours are near, while the middle position is two steps from either end.
Example 2
The value sits at each end again, and reaching two steps inwards from each covers the first three and the last three positions.
Example 3
Every position holds the value, so every position is near.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def find_k_distant_indices(readings: list[int], key: int, k: int) -> list[int]:public List<Integer> findKDistantIndices(int[] readings, int key, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.