← Questions

Fewest guesses in Wordle with green feedback only

0
GoogleCodingLast asked Oct 2025

A coding interview question asked in Google's first round (coding), last asked Oct 2025. It tests search, probability and strings.

A secret five-letter word is drawn from a known dictionary. After each guess you learn only which positions hold the right letter (green); there is no yellow feedback. Write a strategy that picks guesses so the secret is found in as few guesses as possible, on average or in the worst case.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • feedback(guess: str, secret: str) -> tuple[bool, ...] — five flags, True where guess[i] == secret[i].
  • next_guess(candidates: list[str], words: list[str]) -> str — choose the next guess from words (the allowed guesses) given the words still consistent with all feedback so far.
  • solve(secret: str, words: list[str]) -> int — play until the guess equals the secret and return the number of guesses.

Example

feedback("crane", "crate")  ->  (True, True, True, False, True)
feedback("slate", "crate")  ->  (False, False, True, True, True)

candidates = ["crate", "crane", "grate", "slate"]
# guess "crate":  crate -> all green,  crane -> TTTFT,  grate -> FTTTT,  slate -> FFTTT
# every candidate gives a different answer, so one guess identifies the secret

Constraints

  • The dictionary has a few thousand words; the allowed guesses may include words that cannot be the secret.
  • Guesses must be chosen fast enough to play interactively.

Clarifying questions

  • Must every guess be a possible secret, or can I guess any allowed word to gain information?
  • Optimise the average number of guesses or the worst case?
  • Are all secrets equally likely, or do we have word frequencies?
  • Can letters repeat in words?

What a strong answer covers

  • Start from brute force: guess candidates in order, and say why it is slow.
  • Filtering: after each feedback keep only candidates that would produce the same feedback.
  • Choosing a guess by how it splits the candidates: for each guess, bucket candidates by feedback pattern, then minimise the expected remaining size (sum of bucket sizes squared), the largest bucket (worst case), or maximise entropy.
  • A cheap heuristic from per-position letter frequencies, since green-only feedback is independent per position.
  • Cost: O(guesses × candidates × 5) per turn; precompute or sample when the dictionary is large.
  • Tests on the full dictionary: average and maximum guesses.

Follow-ups

  • Add yellow feedback. What changes in the feedback function and the bucketing?
  • Secrets have prior probabilities; weight the buckets.
  • Find the strategy with the provably smallest worst case for a small dictionary (minimax search).

Where it's asked

  • Google · First round: coding · Last asked Oct 202545 min · Coding in a Google Doc, no syntax highlighting or autocomplete · No AI

What it tests

search · probability · strings

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding