Skip to content

Commit

Permalink
Create 1539. Kth Missing Positive Number.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
KashishJuneja101003 authored Jan 31, 2025
1 parent bfeb94c commit bd68c81
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 1539. Kth Missing Positive Number.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public:
int findKthPositive(vector<int>& arr, int k) {
int left = 0, right = arr.size()-1;

while(left <= right){
int mid = left + (right-left)/2;

if(arr[mid]-mid-1 < k){
left = mid+1;
} else{
right = mid-1;
}
}

return left+k;
}
};

0 comments on commit bd68c81

Please sign in to comment.