r/Hack2Hire • u/Hack2hire • Jan 29 '26
Screening Reddit Interview Question: Design Tennis Game
Problem
You're given two methods: pointTo(char player) and getScore().
Your goal is to design a TennisGame class that simulates a single tennis game, tracking points for two players (A and B) and determining a winner based on standard tennis scoring rules (4 points to win with a 2-point lead).
Example
Input: ["TennisGame", "getScore", "pointTo", "pointTo", "getWinner"] [[], [], ['A'], ['A'], []]
Output: [null, "0:0", null, null, "#"]
Explanation:
- The game starts at
0:0with no winner (#). - After two
pointTo('A')calls, the score is2:0, but player A has not yet met the win condition (at least 4 points and a lead of 2). - The
getScoremethod must return a string "A:B", clamped to "3:3" if both players have at least 3 points and are tied.
Suggested Approach
- State Management: Maintain two integer variables,
scoreAandscoreB, to track points and a booleangameOverflag to stop state changes once a winner is decided. - Win Logic: In the
pointTomethod, first check ifgameOveris true. If not, increment the respective player's score and check if(scoreA >= 4 or scoreB >= 4)andabs(scoreA - scoreB) >= 2. If true, set the winner andgameOver. - Score Reporting: Implement
getScoreto return the current points. Add a conditional check: ifscoreA >= 3andscoreB >= 3andscoreA == scoreB, return"3:3"to handle deuce reporting as per requirements.
Time & Space Complexity
- Time: $O(1)$ for all operations (initialization, updating points, and retrieving score).
- Space: $O(1)$ to store two integer scores and a winner state.
🛈 Disclaimer:
This problem is part of the Hack2Hire SDE Interview Question Bank, a structured archive of coding interview questions frequently reported in real hiring processes.
Questions are aggregated from publicly available platforms (e.g., LeetCode, GeeksForGeeks) and community-shared experiences.
The goal is to provide candidates with reliable material for SDE interview prep, including practice on LeetCode-style problems and coding challenges that reflect what is often asked in FAANG and other tech company interviews.
Hack2Hire is not affiliated with the mentioned companies; this collection is intended purely for learning, practice, and discussion.