// dp solution memoization top-down
int f1(int n, vector<int> &heights, vector<int>& dp){
// base case
if(n == 0) return 0;
// for dp memoization if ans is store return ans
if(dp[n] != -1) return dp[n];
// do all possible task that index
int left = f1(n-1,heights, dp) + abs(heights[n]-heights[n-1]);
// the right is not always possible e.g: f(1) declare right = INT_MAX
int right = INT_MAX;
if(n > 1)
right = f1(n-2, heights, dp) + abs(heights[n]-heights[n-2]);
// return the ans according yoyr question
// and store the ans in dp
return dp[n] = min(left, right);
}
int frogJump(int n, vector<int> &heights)
{
// initialize the vector for dp
// vector<int> dp(n+1,-1);
// return f1(n-1,heights,dp);
// tabulization approch
vector<int> dp(n, -1);
// apporch as per base case
dp[0] = 0;
for(int i=1; i<n; i++){
// find first step
int fs = dp[i-1] + abs(heights[i]-heights[i-1]);
// find ss step
int ss = INT_MAX;
if(i > 1) ss = dp[i-2] + abs(heights[i]-heights[i-2]);
// find cur index value
dp[i] = min(fs, ss);
}
return dp[n-1];
}


