2 testcases not working pls check
logic and code both are correct
the run time errror is due to size issue
max size of dp array is 10^3 * 10^5=10^8 which should be declare globally otherwise give runtime error
only change you have to make is declare dp array globally
Modified Code
if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like
: and don’t forgot to mark doubt as resolved 