Problemcricket innings scorer

Session: Sign in to solve

Solution.txt

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 recordDelivery call adds its runs to the run total and increments the legal-ball count once.
  • Count wickets. The wicket total increments once exactly when wicket is true.
  • Report the score. getScorecard returns <totalRuns>/<wickets> (<legalBalls> balls) using the current totals.

API

SignatureReturnsBehavior
CricketInningsScorer()Not applicableCreates a scorer with zero runs, wickets, and legal balls.
recordDelivery(runs: integer, wicket: boolean)voidRecords one legal delivery. runs is from 0 through 6.
getScorecard()stringReturns the current score in the required format.

Examples

StepOperationResult
1CricketInningsScorer()New scorer
2recordDelivery(4, false)void
3recordDelivery(1, false)void
4recordDelivery(0, true)void
5getScorecard()5/1 (3 balls)

Constraints

  • 0 <= runs <= 6.
  • At most 10,000 deliveries are recorded on one scorer.
  • At most 10 recorded deliveries have wicket equal to true.
  • 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.

PRIVATE WORKSPACE

Checking your session…

The statement is public. The editor, editorial, submissions, and saved work are private.