Skip to main content
Back to problems
#3921
Easy Algorithms

Score validator

72.9% acceptance
May 13, 2026
12
2
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.

Solution

Rust
Time O(n)
Space O(n)
LeetCode
solution.rs
impl Solution {
  pub fn score_validator(events: Vec<String>) -> Vec<i32> {
    let mut score = 0i32;
    let mut counter = 0i32;
    for e in &events {
      if counter == 10 { break; }
      match e.as_str() {
        "W" => counter += 1,
        "WD" | "NB" => score += 1,
        s => score += s.parse::<i32>().unwrap(),
      }
    }
    vec![score, counter]
  }
}