[LeetCode] Score Validator

3921. Score Validator

You are given a string array events.

Initially, score = 0 and counter = 0. Each element in events is one of the following:

  • "0", "1", "2", "3", "4", "6": Add that value to the total score.
  • "W": Increase the counter by 1. No score is added.
  • "WD": Add 1 to the total score.
  • "NB": Add 1 to the total score.

Process the array from left to right. Stop processing when either:

  • All elements in events have been processed, or
  • The counter becomes 10.

Return an integer array [score, counter], where:

  • score is the final total score.
  • counter is the final counter value.
1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public:
vector<int> scoreValidator(vector<string>& events) {
int score = 0, counter = 0;
for(int i = 0; i < events.size() and counter < 10; i++) {
if(events[i] == "W") counter++;
else if(events[i].length() == 2) score++;
else score += stoi(events[i]);
}
return {score, counter};
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2026/09/04/PS/LeetCode/score-validator/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.