2200. Find All K-Distant Indices in an Array
On This Page
class Solution:
def findKDistantIndices(self, nums: List[int], key: int, k: int) -> List[int]:
res = []
j, n = 0, len(nums)
for i in range(n):
while j < i - k or (j < n and nums[j] != key):
j += 1
if j < n and j <= (i + k):
res.append(i)
return res