Frog1 problem solving using db

I don’t know whats wrong in my code here it is
#include <bits/stdc++.h>
using namespace std;
int frogTPD(int n,vectorarr,int i){
if(i >= n) return 0;
int op1 = arr[i]-arr[i+1] + frogTPD(n,arr,i+1);
int op2 = arr[i]-arr[i+2] + frogTPD(n,arr,i+1);

return abs(min(op1,op2));

int main()
int n;
cin >> n;
for(int i=0;i<n;i++){
cin >> arr[i];

return 0;


The issue in your code is that the function frogTPD is accessing elements out of bounds of the array arr , causing undefined behavior.

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.