MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / lastocc

Function lastocc

CPP/searching/binary_search1.cpp:26–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25}
26int lastocc(vector<int>& arr,int n,int key){
27 int s=0;
28 int e=n-1;
29 int ans=-1;
30 for (int i = 0; i < n; i++) {
31 int mid=(s+e)/2;
32 if(arr[mid]==key){
33 ans=mid;
34 s=mid+1;
35 }
36 else if(key>arr[mid])
37 s=mid+1;
38 else
39 e=mid-1;
40 }
41 return ans;
42
43}
44
45
46int main(){

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected