AlgoMaster Logo

Guess the Word

Ashish

Ashish Pratap Singh

hard

Problem Description

Solve it on LeetCode

Approaches

1. Random Guess

Intuition:

The simplest solution involves randomly guessing words from the word list. This approach lacks strategic guessing but doesn't require complicated logic. The only check is to ensure you don't guess the same word twice.

Steps:

  1. Randomly select a word from the list of available words.
  2. Call the guess function with the selected random word.
  3. Continue guessing until the correct word is guessed (i.e., guess returns the word length).

Code:

2. Minimax Strategy

Intuition:

A more informed approach is to use minimax to reduce the candidate pool aggressively by minimizing the maximum number of words that could remain after a guess. This strategy leads to fewer guesses by attempting to maximize information gain.

Steps:

  1. Count matches for each possible word against all others.
  2. Choose a word that, on average, splits the possibility space well.
  3. Use guessed similarity (number of letter matches) to filter the list.
  4. Repeat until the correct word is guessed.

Code:

3. Optimal Data Filtering

Intuition:

Incorporating chosen strategic guessing along with data filtering reduces unnecessary guesses significantly. The idea is to reduce candidate words as much as possible each turn.

Steps:

  1. For each guess, calculate the number of matching letters for every pair of words.
  2. Optimize the next guess based on its ability to partition the wordpool efficiently.
  3. Break the loop when guessed successfully.

Code: