We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Hi @sxb427 !
Thank you for the insight!
I was able to implement similar solution iteratively, but cannot see how I can apply DP here! In fact my method never gets called again with the same argument but it still fails on TimeOut when I submit it.
How will memoization help me if I never call the method twice with the same arguments?? (I've tried to catch the same method+args call in code, but no luck!)
privatestaticbooleanisTransformable(Stringa,Stringb){// Trying to catch subsequent method calls:/* if(methodCalls[a.length()][b.length()]) System.out.println("Subsequent call with args " + a.length() + " and " + b.length()); methodCalls[a.length()][b.length()] = true; */if(a.length()<b.length())returnfalse;if(b.length()==0){if(a.toLowerCase().equals(a))returntrue;elsereturnfalse;}StringlastA=a.substring(a.length()-1,a.length());StringlastB=b.substring(b.length()-1,b.length());if(lastA.equals(lastB)||lastA.toUpperCase().equals(lastB))returnisTransformable(a.substring(0,a.length()-1),b.substring(0,b.length()-1))||isTransformable(a.substring(0,a.length()-1),b);else{if(lastA.toLowerCase().equals(lastA))returnisTransformable(a.substring(0,a.length()-1),b);elsereturnfalse;}}
Even for a large input Strings like these, method gets called exactly once with the same params:
Abbreviation
You are viewing a single comment's thread. Return to all comments →
Hi @sxb427 ! Thank you for the insight! I was able to implement similar solution iteratively, but cannot see how I can apply DP here! In fact my method never gets called again with the same argument but it still fails on TimeOut when I submit it. How will memoization help me if I never call the method twice with the same arguments?? (I've tried to catch the same method+args call in code, but no luck!)
Even for a large input Strings like these, method gets called exactly once with the same params: