Skip to content

Commit 7742b0f

Browse files
committed
Jun 24
1 parent 81d030f commit 7742b0f

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution:
2+
def findKDistantIndices(self, nums: list[int], key: int, k: int) -> list[int]:
3+
n = len(nums)
4+
result = []
5+
right = 0
6+
for i in range(n):
7+
if nums[i] != key:
8+
continue
9+
left = max(right, i - k)
10+
right = min(i + k, n - 1) + 1
11+
for j in range(left, right):
12+
result.append(j)
13+
return result
14+
15+
16+
def main():
17+
nums = [3, 4, 9, 1, 3, 9, 5]
18+
key = 9
19+
k = 1
20+
assert Solution().findKDistantIndices(nums, key, k) == [1, 2, 3, 4, 5, 6]
21+
22+
nums = [2, 2, 2, 2, 2]
23+
key = 2
24+
k = 2
25+
assert Solution().findKDistantIndices(nums, key, k) == [0, 1, 2, 3, 4]
26+
27+
28+
if __name__ == '__main__':
29+
main()

2025-06-June-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
| June 21 | [3085. Minimum Deletions to Make String K-Special](https://leetcode.com/problems/minimum-deletions-to-make-string-k-special/) | Medium | Solved |
2828
| June 22 | [2138. Divide a String Into Groups of Size k](https://leetcode.com/problems/divide-a-string-into-groups-of-size-k/) | Easy | Solved |
2929
| June 23 | [2081. Sum of k-Mirror Numbers](https://leetcode.com/problems/sum-of-k-mirror-numbers/) | Hard | Unsolved |
30-
| June 24 | []() | | |
30+
| June 24 | [2200. Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | Solved |
3131
| June 25 | []() | | |
3232
| June 26 | []() | | |
3333
| June 27 | []() | | |
@@ -39,6 +39,6 @@
3939
## Summary
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
42-
| Easy | 3 | 3 | 0 |
42+
| Easy | 4 | 4 | 0 |
4343
| Medium | 10 | 7 | 3 |
4444
| Hard | 6 | 2 | 4 |

0 commit comments

Comments
 (0)