Array Shrinking
HardRating 2100CodeforcesAdvanced DP (Bitmask, Digit, Interval)
Approach hintTry it first, then revealHide
First compute val[l][r], the single value a segment can collapse into, if any, by splitting it into two parts that collapse to the same value. Then a prefix DP partitions the array into the fewest collapsible segments. O(n^3).