Implement a tennis score tracker
AeoneaSoftware Engineer · Technical ScreenLast updated
This question evaluates a candidate's ability to implement stateful scoring logic and choose appropriate data structures for tracking sequential events, specifically handling tennis scoring rules such as 0/15/30/40 progression, Deuce, Advantage, and the two-point lead requirement.
Design and implement a tennis game scoring function. Input: a stream of points won by players 'A' or 'B' (e.g., A, B, B, B, B). After each point, output the current score in tennis notation: 'A 15-0 B', 'A 15-15 B', 'A 15-30 B', 'A 15-40 B', and finally the game result. Handle 0/15/30/40 progression, Deuce, Advantage, and Game with the correct two-point lead rule. Specify your data structures and update logic, and provide the outputs for the given example sequence.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.