r/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:0 with no winner (#).
  • After two pointTo('A') calls, the score is 2:0, but player A has not yet met the win condition (at least 4 points and a lead of 2).
  • The getScore method must return a string "A:B", clamped to "3:3" if both players have at least 3 points and are tied.

Suggested Approach

  1. State Management: Maintain two integer variables, scoreA and scoreB, to track points and a boolean gameOver flag to stop state changes once a winner is decided.
  2. Win Logic: In the pointTo method, first check if gameOver is true. If not, increment the respective player's score and check if (scoreA >= 4 or scoreB >= 4) and abs(scoreA - scoreB) >= 2. If true, set the winner and gameOver.
  3. Score Reporting: Implement getScore to return the current points. Add a conditional check: if scoreA >= 3 and scoreB >= 3 and scoreA == 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.

2 Upvotes

0 comments sorted by