From 06abe2a6f63edad5e9c37b61d2d1530ce8fec2da Mon Sep 17 00:00:00 2001 From: chayan das Date: Tue, 24 Jun 2025 20:58:39 +0530 Subject: [PATCH] Create 2200. Find All K-Distant Indices in an Array --- 2200. Find All K-Distant Indices in an Array | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 2200. Find All K-Distant Indices in an Array diff --git a/2200. Find All K-Distant Indices in an Array b/2200. Find All K-Distant Indices in an Array new file mode 100644 index 0000000..dff73b6 --- /dev/null +++ b/2200. Find All K-Distant Indices in an Array @@ -0,0 +1,20 @@ +class Solution { +public: + vector findKDistantIndices(vector& nums, int key, int k) + { + vector ans; + int n = nums.size(), last_index = 0; + for(int j = 0; j < n; j++) + { + if(nums[j] == key) + { + int start = max(last_index, j - k); + int end = min(j + k + 1, n); + for(int i = start; i < end; i++) + ans.push_back(i); + last_index = end; + } + } + return ans; + } +};