When i was submitting my solution in leetcode, I was getting TLE when passing string by value but after changing it to string by reference it got faster. I thought strings were passes by refence automatically anyways. Below are images of code being accepted and not accepted.
Reference passes the same copy of the dp array. Pass by value creates new dp array each time the function is called. So, it takes more time and memory.