Problem 56513. Cricket - Peak Batting Average
Given a vector s of strings representing a batter's individual innings scores (in chronological order), return the highest batting average they achieved in their career, ignoring any undefined or infinite averages. (You can assume that every batter will be dismissed at least once in their career, but not necessarily in their first innings.) The strings will be in the form of a number ("42") or a number with an asterisk ("42*") to represent "not-out".
Batting average is defined as total runs divided by number of dismissals (ie number of innings - number of not-outs).
For example, if s = ["81","99*","57","118*","36*","0","18","10","61*","0","83*","24","10*"]:
- After their first innings, the batter has an average of 81
- After their second, their average is 180 (81 + 99 runs, with still only one dismissal)
- After their third, 118.5 (237 runs, two dismissals)
- Fourth, 177.5 (355 runs, still two dismissals)
- Fifth, 195.5 (391/2)
- Sixth, 130.3 (391/3)
- etc
Hence, their career maximum was after their fifth innings: 195.5.
maxavg = maxbattingavg(s)
maxavg =
195.5000
Similarly,
s = ["17*","12*","14","59","6*","0","18"];
maxavg = maxbattingavg(s)
maxavg =
54
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers26
Suggested Problems
-
1583 Solvers
-
Generate N equally spaced intervals between -L and L
865 Solvers
-
328 Solvers
-
295 Solvers
-
468 Solvers
More from this Author22
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!