Apply Score-Record Operations and Sum the Remaining Scores

Quick Overview

Apply Score-Record Operations and Sum the Remaining Scores. Start with an empty score record.

Apply Score-Record Operations and Sum the Remaining Scores

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Start with an empty score record. An integer token appends that score; + appends the sum of the latest two remaining scores; D appends twice the latest remaining score; C removes the latest remaining score. Return the final sum. Operations are valid, and the source guarantees the answer and all intermediate calculations fit signed 32-bit int. ```cpp class Solution { public: int calPoints(vector<string>& operations); }; ``` ### Examples **Example 1:** ```text operations = ["3","4","D","+"] Output: 27 Explanation: The record becomes [3,4,8,12]. ``` **Example 2:** ```text operations = ["-2","5","C","D"] Output: -6 Explanation: Removing 5 leaves -2, so D appends -4. ``` ### Constraints - Operation count: 1..1000. Tokens are C, D, +, or decimal integers in -30000..30000. A + token always has two prior remaining scores; C and D each have at least one. All operations and signed-32-bit calculations satisfy the source guarantee stated above. ### Clarifying Questions Base each derived score on the current remaining record and preserve the source's intermediate-fit promise. ```hint Read the boundary condition Which container supports both reading the last two scores and undoing the latest one? ``` ### Contract considerations Base each derived score on the current remaining record and preserve the source's intermediate-fit promise.

Overview: Apply Score-Record Operations and Sum the Remaining Scores. Start with an empty score record.

Google logo
Google
Sep 10, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Start with an empty score record. An integer token appends that score; + appends the sum of the latest two remaining scores; D appends twice the latest remaining score; C removes the latest remaining score. Return the final sum. Operations are valid, and the source guarantees the answer and all intermediate calculations fit signed 32-bit int.

class Solution {
public:
    int calPoints(vector<string>& operations);
};

Examples

Example 1:

operations = ["3","4","D","+"]
Output: 27
Explanation: The record becomes [3,4,8,12].

Example 2:

operations = ["-2","5","C","D"]
Output: -6
Explanation: Removing 5 leaves -2, so D appends -4.

Constraints

  • Operation count: 1..1000. Tokens are C, D, +, or decimal integers in -30000..30000. A + token always has two prior remaining scores; C and D each have at least one. All operations and signed-32-bit calculations satisfy the source guarantee stated above.

Clarifying Questions Guidance

Base each derived score on the current remaining record and preserve the source's intermediate-fit promise.

Contract considerations

Base each derived score on the current remaining record and preserve the source's intermediate-fit promise.