Skip to content

Commit abcb58f

Browse files
Merge pull request #128 from kumarvivek8/patch-9
Create findingupperboundandlowerbound.cpp
2 parents 6ce3fe6 + ae767e6 commit abcb58f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

findingupperboundandlowerbound.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include<iostream>
2+
#include<algorithm>
3+
using namespace std;
4+
int main()
5+
{
6+
long long int n;
7+
cin>>n;
8+
long long int a[n];
9+
for(int i=0;i<n;i++)
10+
{
11+
cin>>a[i];
12+
}
13+
int q;
14+
cin>>q;
15+
while(q--)
16+
{
17+
long long int key;
18+
cin>>key;
19+
if(binary_search(a,a+n,key))
20+
{
21+
int lb=lower_bound(a,a+n,key)-a;
22+
int ub=upper_bound(a,a+n,key)-a-1;
23+
cout<<lb<<" "<<ub<<" "<<endl;
24+
}
25+
else
26+
cout<<"-1"<<" "<<"-1"<<endl;
27+
}
28+
}

0 commit comments

Comments
 (0)