Find a hidden word in at most 10 guesses from position-match feedback

Quick Overview

Find a hidden six-letter word among up to 100 unique candidates using at most 10 guesses, where each guess reveals only how many positions match the secret. Tests filtering a candidate pool by feedback, choosing guesses that shrink the pool in the worst case, and reasoning about lists no strategy can solve in time.

Find a hidden word in at most 10 guesses from position-match feedback

Company: Patreon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

You are given a list of unique candidate words, `words`. Every word has exactly 6 lowercase letters, and one of them is the hidden `secret`. You find the secret by guessing words. After each guess you learn only one thing: the number of positions where the guess and the secret have the same letter, a value from 0 to 6. Write `find_secret_word(words, secret)`, which plays this game and returns the secret within at most 10 guesses. If the secret has not been found after 10 guesses, return the empty string `""`. The secret is passed in only so the game can be simulated locally. Your strategy may learn about it only through a helper that scores one guess against it, and every call to that helper counts as a guess. Example 1: ```text Input: words = ["acckzz","ccbazz","eiowzz","abcczz"], secret = "acckzz" Output: "acckzz" ``` "acckzz" matches the other three words in 3, 2 and 4 positions. Those counts are all different, so after guessing it, at most one candidate is left whatever the feedback is. A strategy that picks it first finds the secret with one guess. Example 2: ```text Input: words = ["hamada","khaled"], secret = "hamada" Output: "hamada" ``` The two words have no letter in the same position. If the first guess is "khaled", the feedback is 0, which rules out "khaled" and leaves "hamada" for the second guess. ```hint What the feedback tells you After a guess with feedback m, the secret matches that guess in exactly m positions. Which candidates can you throw away? ``` ```hint Choosing the next guess A guess splits the remaining candidates into groups by their match count with it. You cannot choose which group the feedback points to, so look at the size of the largest group. ``` ```hint Why an arbitrary guess is slow For two random words, a given position matches with probability 1/26, so a feedback of 0 is the most common outcome. Count how many candidates a 0 usually leaves behind. ``` ### Constraints & Assumptions - `1 <= words.length <= 100` - `words[i].length == 6`, and every word consists of lowercase English letters. - All words in `words` are unique, and `secret` is one of them. - At most 10 guesses are allowed. If the secret is still unknown after 10 guesses, return `""`. ### Clarifying Questions to Ask - Must every guess be a word from `words`, or may I guess any 6-letter string? - Does the guess that hits the secret (feedback 6) count toward the 10? - Are the word lists random, or can they be built to defeat a strategy, for example many words that differ in a single position? - Is the goal to pass every given list, or to minimize the worst-case or the expected number of guesses? ### What a Strong Answer Covers - Filters the candidate pool with each feedback value and explains why the secret is never filtered out. - Picks each guess by a stated rule and justifies it with the worst-case size of the pool that remains. - Explains why guessing an arbitrary or first-in-list word wastes guesses on typical word lists. - Gives the time and space cost per round and overall for up to 100 words. - Recognizes that no strategy can finish within 10 guesses on every possible list and handles the `""` case. ### Follow-up Questions - How would you change the strategy if words already ruled out could still be used as guesses? - How would you precompute the pairwise match counts, and what does that save per round? - How would you choose guesses to minimize the expected number of guesses instead of the worst case? - What changes if words have length L, the alphabet has size A, and the guess budget depends on n?

Overview: Find a hidden six-letter word among up to 100 unique candidates using at most 10 guesses, where each guess reveals only how many positions match the secret. Tests filtering a candidate pool by feedback, choosing guesses that shrink the pool in the worst case, and reasoning about lists no strategy can solve in time.

Patreon logo
Patreon
Nov 25, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

You are given a list of unique candidate words, words. Every word has exactly 6 lowercase letters, and one of them is the hidden secret. You find the secret by guessing words. After each guess you learn only one thing: the number of positions where the guess and the secret have the same letter, a value from 0 to 6.

Write find_secret_word(words, secret), which plays this game and returns the secret within at most 10 guesses. If the secret has not been found after 10 guesses, return the empty string "". The secret is passed in only so the game can be simulated locally. Your strategy may learn about it only through a helper that scores one guess against it, and every call to that helper counts as a guess.

Example 1:

Input: words = ["acckzz","ccbazz","eiowzz","abcczz"], secret = "acckzz"
Output: "acckzz"

"acckzz" matches the other three words in 3, 2 and 4 positions. Those counts are all different, so after guessing it, at most one candidate is left whatever the feedback is. A strategy that picks it first finds the secret with one guess.

Example 2:

Input: words = ["hamada","khaled"], secret = "hamada"
Output: "hamada"

The two words have no letter in the same position. If the first guess is "khaled", the feedback is 0, which rules out "khaled" and leaves "hamada" for the second guess.

Constraints & Assumptions

  • 1 <= words.length <= 100
  • words[i].length == 6 , and every word consists of lowercase English letters.
  • All words in words are unique, and secret is one of them.
  • At most 10 guesses are allowed. If the secret is still unknown after 10 guesses, return "" .

Clarifying Questions to Ask Guidance

  • Must every guess be a word from words , or may I guess any 6-letter string?
  • Does the guess that hits the secret (feedback 6) count toward the 10?
  • Are the word lists random, or can they be built to defeat a strategy, for example many words that differ in a single position?
  • Is the goal to pass every given list, or to minimize the worst-case or the expected number of guesses?

What a Strong Answer Covers Guidance

  • Filters the candidate pool with each feedback value and explains why the secret is never filtered out.
  • Picks each guess by a stated rule and justifies it with the worst-case size of the pool that remains.
  • Explains why guessing an arbitrary or first-in-list word wastes guesses on typical word lists.
  • Gives the time and space cost per round and overall for up to 100 words.
  • Recognizes that no strategy can finish within 10 guesses on every possible list and handles the "" case.

Follow-up Questions Guidance

  • How would you change the strategy if words already ruled out could still be used as guesses?
  • How would you precompute the pairwise match counts, and what does that save per round?
  • How would you choose guesses to minimize the expected number of guesses instead of the worst case?
  • What changes if words have length L, the alphabet has size A, and the guess budget depends on n?