Implementation in 1-D DP in Flood Fill

Sir, I went through hint, and implemented the code in 2D DP, but unable pass 1 testcase, where it is giving TLE. Could you help me approach the problem in 1D DP.

Sir, any updates on the topic?

refer to this for understanding concept

code

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.