[InterviewBit] Search for a Range

Search for a Range

  • Time :
  • Space :
1
2
3
4
5
6
7
vector<int> Solution::searchRange(const vector<int> &A, int B) {
auto l = lower_bound(begin(A), end(A), B) - begin(A);
auto r = upper_bound(begin(A), end(A), B) - begin(A) - 1;
if(0 <= l and l < A.size() and A[l] == B) return {l,r};
return {-1,-1};
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/09/30/PS/interviewbit/search-for-a-range/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.