How the case came
when a[l]==a[r], dp[l][r]=1+dp[l+1][r-1]
It means that had made the component of same color from l+1 to r-1 and now we are merging them then also it will take 2+dp[l+1][r-1]
Flood fill How the case came when a[l]==a[r], dp[l][r]=1+dp[l+1][r-1]
Hello !
Notice this condition given in the statement :
Then, in each game turn, change the color of the connected component containing the starting square to any other color.
Now you can just notice that the actual color doesnt matter and you would just need one move to change the color of [l + 1,r- 1]segment to a single color that is equal to the adjacent colors. So its like dp[l + 1][r - 1] is equal to min moves to let that segment be of any color. and then you make 1 one to get that segment equal to this color.
In other words you can see that spending 1 move to get inside segment to this color not the other ones on the extreme ends
Hope that would have helped ! Feel free to ask back : )
(If the doubt was resolved please close the doubt and rate the experience : )
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.