I ran this code over leetcode
class Solution {
int peakPresent(vector a, int n, int s, int e){
if(s < 0 || e == n){
return -1;
}
if(s <= e){
int mid = (s+e)/2;
if( mid == 0 && a[mid+1] < a[mid]){
// cout<<mid<<endl;
return mid; }
else if( mid == n-1 && a[mid-1] < a[mid]){
// cout<<mid<<endl;
return mid;}
else if(a[mid-1] < a[mid] && a[mid] > a[mid+1]){
// cout<<mid<<endl;
return mid;}
else if(a[mid+1] > a[mid]) {
// cout<<mid<<"\tright"<<endl;
return peakPresent(a,n,mid+1,e);}
else{
// cout<<mid<<"\tleft"<<endl;
return peakPresent(a,n,s,mid);}
}
return -1;
}
public:
int findPeakElement(vector& a) {
if(a.size() == 1 )
return 0;
return peakPresent(a,a.size(),0,a.size()-1);
}
};
and it is showing
Line 924: Char 34: runtime error: addition of unsigned offset to 0x602000000370 overflowed to 0x60200000036c (stl_vector.h)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/…/lib/gcc/x86_64-linux-gnu/8/…/…/…/…/include/c++/8/bits/stl_vector.h:933:34
over input: 1,2