can anyone tell the error? its giving me a heap memory overflow

class Solution {
public:
int maxProfit(vector& prices) {
int i;
int start=0;
int end=prices.size();

    while(prices[start]>prices[start+1]&&start!=end-2)
    {
        start++;
    }
   
    if(start==end-2)
    {
        return 0;
    }
    else
    {
         int m=0;
    for(int j=start+1;j<end;j++)
    {
        m=max(m,prices[j]);
    }
        return m-prices[start];
    }
    
}

};

Comments (1)