Dont undersand why LeetCode is showing RE

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

@Hyperian can you send the question link

@Hyperian binary search will not work for this question, you have to do a linear search and check if a[I] >a[I+1] and a[I] < a[i-1] return i

it is mentioned in the question to use logn approach. Moreover, the dry run is working fine. Why its showing RE.

@Hyperian you are getting re because when mid==0
array [1,2]
since a[0] is not less than a[1];
code goes to the third condition where you have wrote a[mid-1] which is -1,
so you are getting re

@Hyperian third condition should be
else if(mid!=0&&mid!=a.size()-1&&a[mid-1] < a[mid] && a[mid] > a[mid+1]){
// cout<<mid<<endl;
return mid;}

that worked thanks for the help

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.