Tap here to switch tabs
Problem
Submissions

Problem: Score Validator

med
30 min
Try to solve the Score Validator problem.

Statement

You are given an array of strings events representing a sequence of occurrences in a cricket match.

You need to track the total runs scored and the total wickets fallen. Starting with both runs and wickets equal to 00, process the elements in events sequentially according to the following rules:

  • "0", "1", "2", "3", "4", or "6": Add the corresponding numerical value to the total runs.

  • "WD": A wide delivery. Add 11 run to the total runs.

  • "NB": A no ball delivery. Add 11 run to the total runs.

  • "W": A wicket delivery. Add 11 to the wicket count.

If the wicket count reaches 1010, the innings ends immediately, and all subsequent events are ignored.

Return an integer array in the format [total_runs, total_wickets].

Constraints:

  • 1≤1 \leq events.length ≤1000\leq 1000

  • events[i] is one of "0", "1", "2", "3", "4", "6", "W", "WD", or "NB".

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Score Validator

med
30 min
Try to solve the Score Validator problem.

Statement

You are given an array of strings events representing a sequence of occurrences in a cricket match.

You need to track the total runs scored and the total wickets fallen. Starting with both runs and wickets equal to 00, process the elements in events sequentially according to the following rules:

  • "0", "1", "2", "3", "4", or "6": Add the corresponding numerical value to the total runs.

  • "WD": A wide delivery. Add 11 run to the total runs.

  • "NB": A no ball delivery. Add 11 run to the total runs.

  • "W": A wicket delivery. Add 11 to the wicket count.

If the wicket count reaches 1010, the innings ends immediately, and all subsequent events are ignored.

Return an integer array in the format [total_runs, total_wickets].

Constraints:

  • 1≤1 \leq events.length ≤1000\leq 1000

  • events[i] is one of "0", "1", "2", "3", "4", "6", "W", "WD", or "NB".