DP

 fibaonaci series using dp

class Solution {
public int usingDp(int n, int dp[])
{
if(n <= 1)
return n ;

if(dp[n] != -1)
return dp[n];

return dp[n]=usingDp(n-1,dp) + usingDp(n-2,dp);
}
public int fib(int n) {
int [] dp ={n+1,-1};
int no = usingDp(n, dp);
return no;
}
}

TC = o(n) linear

SC = o(n)+o(n) {array, stack space for recur}






Comments

Popular posts from this blog

Intellect Interview Experience

Google

Accolite digital Interview experience