Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<int> find(int arr[], int n , int x )
- {
- vector<int>v;
- int l=0,r=n-1,mid,flg=0;
- int mn=n-1;
- while(l<=r)
- {
- mid=(l+r)/2;
- if(arr[mid]==x) flg=1;
- if(arr[mid]>=x)
- {
- mn=min(mn,mid);
- r=mid-1;
- }
- else l=mid+1;
- }
- l=0,r=n-1;
- int mx=0;
- while(l<=r)
- {
- mid=(l+r)/2;
- if(arr[mid]<=x)
- {
- mx=max(mx,mid);
- l=mid+1;
- }
- else r=mid-1;
- }
- if(flg==0)
- {
- v.push_back(-1);
- v.push_back(-1);
- }
- else
- {
- v.push_back(mn);
- v.push_back(mx);
- }
- return v;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement