Remove Color Boxes Problem

Remove Color Boxes Problem — ExecCode Hard DSA Practice

Solve the Remove Color Boxes problem on ExecCode. Free online hard DSA practice in DP. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Boxes of colors stand in a row. A move removes a contiguous group of the same color of length k (k>=1) and scores k*k. Remaining boxes close the gap. Maximize the score. Return the maximum score. You are given: boxes — array of color ids Return integer score. Same colors that were not adjacent can become adjacent later.

Examples

Input {'boxes': [1, 3, 2, 2, 2, 3, 4, 3, 1]}; Output 23. Input {'boxes': [1, 1, 1]}; Output 9. Input {'boxes': [1]}; Output 1

Constraints

You may remove a single box (score 1) After a removal the array concatenates

Practice Remove Color Boxes free on ExecCode. Browse DSA problems, topic map, and placement guides.