Grokking Dynamic Programming Patterns for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Code is not quite right for top down should be this the other way you get inccorect result

alik.dudin

Sep 26, 2025

private int dyn(String st,int startIndex , int endIndex, Integer[][] dp){ if(startIndex == endIndex){ return 1; } if(startIndex>endIndex){ return 0; } if(dp[startIndex][endIndex]!=null){ return dp[startIndex][endIndex]; } if(st.charAt(startIndex) == st.charAt(endIndex)&& endIndex-startIndex-1==dyn(st,startIndex+1,endIndex-1,dp)){ dp[startIndex][endIndex] = 2+endIndex-startIndex-1; return dp[startIndex][endIndex]; }else{ dp[startIndex][endIndex] = Math.max(dyn(st,startIndex+1,endIndex,dp),dyn(st,startIndex,endIndex-1,dp)); } return dp[startIndex][endIndex]; }

0

0

Comments
Comments

On this page