Baseball Game
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 are keeping score for a game with unusual rules. Scoring starts with an empty record, and you process the strings in operations one by one:
- An integer string "x" records a new score of x (it may be negative).
- "+" records a new score equal to the sum of the two most recent scores.
- "D" records a new score equal to double the most recent score.
- "C" cancels the most recent score, removing it from the record.
Every operation is guaranteed to be valid (for example, "+" always has two scores available). Return the sum of all scores left in the record after all operations (0 if the record is empty).
Examples
Constraints
- 1 <= operations.length <= 1000
- Integer operations are in the range [-3 * 10^4, 3 * 10^4].
- All intermediate scores fit in a 32-bit signed integer.
- Every operation is valid for the current record.
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.