Remove Boxes
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You have a row of boxes, where boxes[i] is the colour of the i-th box. In one move you pick a maximal run of t adjacent boxes that all share a colour, remove the whole run, and score t * t points. The boxes on either side of the removed run then become adjacent.
Keep removing runs until no boxes are left. Return the maximum total score you can get.
A polynomial-time solution is expected (around O(n^4) worst case).
Examples
Constraints
- 1 <= boxes.length <= 100
- 1 <= boxes[i] <= 100
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.