Doubt in memoization

Good Morning…
I am solving this question from leetcode.

  1. Longest Happy String

Here i have come up with the recursive approch, but as i am using void function to solve this question. I am not getting idea how to memoize it.
Please look at my code, and suggest me some idea , how to memoize it, i have submitted this on leetcode, it is showing TLE.
This is my code…

Check the number of changing parameters in your recursive function first. They are a,b and c. So a 3D dp can work here.

I have used 3d DP, But it is showing wrong answer.
Have a look at this code…


Thanks

May be 4 parameters are changing… What do you say??

This is the memoization code for recursion…
It is considering all three integer and one string loo, but this memoization is also showing TLE.
This is the code…


Thanks

I will try this question on my end as well and will tell you.


Please refer to this solution. Its easy to understand.

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.