Cricket over ledger
EasyOnline Assessment
Write up the bowler's figures, over by over, from a ball-by-ball log of a cricket match.
An over is made of six legal deliveries. Wides and no-balls are not legal: they are extra deliveries that the bowler must bowl again. Each delivery is a string:
"0"to"6": a legal delivery; that many runs came off the bat."W": a legal delivery that took a wicket and scored no runs."b1"to"b4": a legal delivery on which the batters ran that many byes."wd"or"wd<n>": a wide, which costs1 + nruns (n = 0when no number follows)."nb"or"nb<n>": a no-ball, which costs1 + nruns (nruns came off the bat).
Runs charged to the bowler are the bat runs, plus everything a wide or a no-ball costs. Byes are not charged to the bowler.
An over ends right after its sixth legal delivery; the next delivery in the log, whatever it is, starts the next over. The log may end in the middle of an over. A wicket on a legal delivery counts as one wicket for the over. An over is a maiden when it has all six legal deliveries and the bowler was charged zero runs in it.
Input: deliveries, a list of strings in the order they were bowled.
Output: a list with one entry [legal, charged, wickets, maiden] for each over that has at least one delivery, in order. maiden is 1 or 0. Return [] for an empty log.
Example 1
- Input:
- [["0","0","W","0","0","0","wd","4","nb","2","1","0","0"]]
- Output:
- [[6,0,1,1],[5,9,0,0]]
- Explanation
- The first six deliveries are all legal and give no runs, so over 1 is
[6, 0, 1, 1]: a wicket costs no runs and the over is still a maiden. In over 2 the wide costs 1, the4costs 4, the no-ball costs 1, then2,1,0and0follow. Only five of those are legal, so the over is unfinished:[5, 9, 0, 0].
Example 2
- Input:
- [["b4","0","0","0","0","0","wd2","nb3","W"]]
- Output:
- [[6,0,0,1],[1,7,1,0]]
- Explanation
- The four byes are not charged to the bowler, so the first over is a maiden. The wide
wd2costs 3 and the no-ballnb3costs 4. They come after the sixth legal delivery, so they belong to the next over, which also contains the wicket:[1, 7, 1, 0].
Example 3
- Input:
- [["nb","0","0","0","0","0","0","wd"]]
- Output:
- [[6,1,0,0],[0,1,0,0]]
- Explanation
- The no-ball costs a run, so the first over is not a maiden even though every bat delivery scored nothing. The final wide is bowled after that over was complete, so it opens an over with no legal deliveries:
[0, 1, 0, 0].
Constraints
0 <= deliveries.length <= 1,000- every delivery is
"0"to"6","W","b1"to"b4","wd","wd1"to"wd6","nb"or"nb1"to"nb6"