This is a DFS approach to a problem , I know it can be done using DP but i want to calculate complexity of this i think it be n^2 , what are the good resources to learn calculation of tc
class Solution {
public boolean canJump(int[] nums,int sum,boolean isreach[]) {
if(sum == nums.length-1){
return true;
}
if(sum >= nums.length){
return false;
}
if(isreach[sum]) return true;
int j = nums[sum];
int k = 1;
boolean check = false;
while( k <= j && sum + k < nums.length ){
check = check || canJump(nums, sum+k,isreach);
if(check) {isreach[sum] = check; return true;}
k++;
}
return false;
}
public boolean canJump(int[] nums) {
boolean isreach[] = new boolean[nums.length];
return canJump(nums,0,isreach);
}
}