cubes.
In one move you pick any contiguous stretch of cubes that are all **the same color** and remove the whole stretch. If it held t cubes, you earn t · t points. The remaining cubes close the gap, so the cubes on either side of the removed stretch become neighbors.
You keep making moves until the row is empty. Return the maximum total score you can achieve.cubes=[3, 1, 1, 3, 2, 3] → 14
Remove the two 1s (4 points), then the 2 (1 point): the three 3s meet and give 9 points. Total 4 + 1 + 9 = 14.
cubes=[5, 5, 5, 5] → 16
All cubes share a color, so one move clears them: 4 · 4 = 16.
cubes=[1, 2, 3] → 3
No two cubes match, so each one is worth 1 point.
cubes=[3, 1, 1, 3, 2, 3]
14
Run checks the first 3 tests in your browser. Submit checks all 125 tests on the server, hidden ones included.