Maximum jumps required -------

please tell me where i am wrong i have used this approach which strikes my mind tell me where i am wrong

#include<bits/stdc++.h>
using namespace std;

int dp[1005][1005]={0};
int max_jump(int* arr,int i,int j,int n){
if(j>=n-1){
return 0;
}
if(dp[i][j]!=-1){
return dp[i][j];
}
int ans=INT_MAX;
for(int k=i+1;k<=j;k++){
ans=min(ans,1+max_jump(arr,k,arr[k]+k,n));
//cout<<ans<<" “<<i<<” "<<j<<endl;
}
dp[i][j]=ans;
return ans;
}
int main() {
int t,n;
cin>>t;
while(t–){
cin>>n;
memset(dp,-1,sizeof(dp));
int* arr=new int[n+1];
for(int i=0;i<n;i++){
cin>>arr[i];
}
cout<<max_jump(arr,0,arr[0],n)+1<<endl;
}
return 0;
}

Please provide your code in coding blocks IDE.

https://ide.codingblocks.com/s/189026
I have corrected your code, you were in particular missing the case when a[i]=0
also there is no need to use 2D array

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.

link:-https://ide.codingblocks.com/s/195485 plz tell me where i am wrong

final code-------------

@riprogerdep is this the final code? or does the link contain the previous code by mistake

its final bro------------

link is same i have changed and updated

@riprogerdep your methods seems okay, but you need to use DP, without DP you will get TLE.


Here is the code utilizing DP, you can refer this.
I also show your code in text above in that you are using 2D DP, which is not required, as here state is defined by only step number so 1 D dp.
If this resolves your doubt mark it as resolved.