Why it is showing runtime?

Can u pls send c++ code of the above problem.

sorry , i only code in java

@Muskan-Gupta-598128740703036
There was a minor issue with the testcases. I have fixed that. However your code still gives TLE for 2 testcases. Make some modifications.
Hint : Initialise DP array to -1 or some other invalid value. 0 is a valid value for the given problem.