Cricket Innings Scorer
Problem
Design CricketInningsScorer to record legal deliveries for one cricket innings and report its current score.
Requirements
- Empty innings. A new scorer reports
0/0 (0 balls). - Record a delivery. Each
recordDeliverycall adds its runs to the run total and increments the legal-ball count once. - Count wickets. The wicket total increments once exactly when
wicketistrue. - Report the score.
getScorecardreturns<totalRuns>/<wickets> (<legalBalls> balls)using the current totals.
API
| Signature | Returns | Behavior |
|---|---|---|
CricketInningsScorer() | Not applicable | Creates a scorer with zero runs, wickets, and legal balls. |
recordDelivery(runs: integer, wicket: boolean) | void | Records one legal delivery. runs is from 0 through 6. |
getScorecard() | string | Returns the current score in the required format. |
Examples
| Step | Operation | Result |
|---|---|---|
| 1 | CricketInningsScorer() | New scorer |
| 2 | recordDelivery(4, false) | void |
| 3 | recordDelivery(1, false) | void |
| 4 | recordDelivery(0, true) | void |
| 5 | getScorecard() | 5/1 (3 balls) |
Constraints
0 <= runs <= 6.- At most 10,000 deliveries are recorded on one scorer.
- At most 10 recorded deliveries have
wicketequal totrue. - All totals fit in a signed 32-bit integer.
Notes
All recorded deliveries are legal balls. Extras, players, overs, match completion, persistence, and concurrent calls are out of scope. Calls execute in order.