diff --git a/Day-26/q3: Find first and last position of element in sorted array/Akansha--C.cpp b/Day-26/q3: Find first and last position of element in sorted array/Akansha--C.cpp new file mode 100644 index 00000000..fa1cde30 --- /dev/null +++ b/Day-26/q3: Find first and last position of element in sorted array/Akansha--C.cpp @@ -0,0 +1,12 @@ +class Solution { +public: + vector searchRange(vector& nums, int target) { + if(binary_search(nums.begin(),nums.end(),target)) + { + int idx=lower_bound(nums.begin(),nums.end(),target)-nums.begin(); + int idx1=upper_bound(nums.begin(),nums.end(),target)-nums.begin(); + return {idx,idx1-1}; + } + return {-1,-1}; + } +}; \ No newline at end of file