Build a hit/miss word guessing game
Word Guessing Game
Two players engage in a word guessing game:
- Player A selects a secret word.
- Player B repeatedly guesses single letters.
- After each guess, the game reports:
- hit: if the secret word contains the guessed letter. All occurrences of that letter are then revealed in the current pattern.
- miss: otherwise. The letter is added to a
misseslist.
The interviewer will provide an example interaction to confirm expected behavior.
Part 1: Implement the Game Engine
Design and implement the necessary data structures and functions to support the following functionalities:
- Initializing a new game with a given secret word.
- Processing a guessed letter and returning the updated game state.
- Tracking the currently revealed letters (e.g., displaying a pattern like
_ _ a _ a). - Tracking all missed letters, maintaining their insertion order.
Inputs/Outputs (Example Shape)
- Input:
secretWord, followed by a sequence of guessed letters. - Output after each guess: An object
{ result: "hit"|"miss", pattern, misses }.
Part 2: Follow-up — Dynamic Secret Word
Now, Player A is permitted to change the secret word at any point during the game. The only constraint is that any new secret word must remain entirely consistent with all previous game responses (i.e., all prior hits, misses, and the currently revealed pattern).
Player B's objective is to minimize the total number of guesses required to definitively determine the secret word.
Discuss a strategic approach and provide high-level pseudocode for Player B to achieve this objective.
Assumptions (to be clearly stated by the candidate):
- There is a known dictionary or set of candidate words, all of the same length.
- Only single letter guesses are allowed (full-word guesses are not, unless explicitly added as a rule).
- The behavior for repeated letter guesses (whether they are allowed, ignored, or re-processed) should be specified by the candidate.
AI interview prep
Core dilemma
The central engineering conflict is balancing efficient state management and updates in Part 1 with the complex algorithmic challenge of optimal information gain and consistency maintenance in Part 2, where the 'secret word' is dynamic and potentially adversarial.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Build a hit/miss word guessing game
Word Guessing Game
Two players engage in a word guessing game:
- Player A selects a secret word.
- Player B repeatedly guesses single letters.
- After each guess, the game reports:
- hit: if the secret word contains the guessed letter. All occurrences of that letter are then revealed in the current pattern.
- miss: otherwise. The letter is added to a
misseslist.
The interviewer will provide an example interaction to confirm expected behavior.
Part 1: Implement the Game Engine
Design and implement the necessary data structures and functions to support the following functionalities:
- Initializing a new game with a given secret word.
- Processing a guessed letter and returning the updated game state.
- Tracking the currently revealed letters (e.g., displaying a pattern like
_ _ a _ a). - Tracking all missed letters, maintaining their insertion order.
Inputs/Outputs (Example Shape)
- Input:
secretWord, followed by a sequence of guessed letters. - Output after each guess: An object
{ result: "hit"|"miss", pattern, misses }.
Part 2: Follow-up — Dynamic Secret Word
Now, Player A is permitted to change the secret word at any point during the game. The only constraint is that any new secret word must remain entirely consistent with all previous game responses (i.e., all prior hits, misses, and the currently revealed pattern).
Player B's objective is to minimize the total number of guesses required to definitively determine the secret word.
Discuss a strategic approach and provide high-level pseudocode for Player B to achieve this objective.
Assumptions (to be clearly stated by the candidate):
- There is a known dictionary or set of candidate words, all of the same length.
- Only single letter guesses are allowed (full-word guesses are not, unless explicitly added as a rule).
- The behavior for repeated letter guesses (whether they are allowed, ignored, or re-processed) should be specified by the candidate.