Flood Fill problem

Not getting an approach to solve this question.
please tell approach.

Intention: Give you an array, you can change all adjacent and identical numbers to another number each time, and finally make all the numbers equal, and ask how many times you want to change at least.

IDEA: I just started to use memory search, but I thought it would become the interval dp, because its label is dp, so the state behind it can be transferred from the previous state, then this question is the smallest of a range. The value can be transferred from the minimum value of another interval. We assume that the current interval has all become a number. Then the next interval is either expanded to the left or expanded to the right because the outer interval is unknown, so we Be sure to change the value inside to the same value as the outermost value of the interval, but if… 2 3 2 3 … this does not know which side has changed, we need to maintain the two ends, count dp[i][j ][0] is the minimum required for this interval to change with the left side as the credential. dp[i][j][1] is the minimum required for the interval from i to j to change from the right endpoint. Then the previous 2 3 2 3 dp[1][3][0] can be directly transferred by dp[2][3][1], or dp[2][3][0]+1 is transferred.

Reference Code

if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like :heart:: and don’t forgot to mark doubt as resolved :grinning: