FastPrepChoose the Next Hidden-Word Guess
Problems/Choose the Next Hidden-Word Guess

Choose the Next Hidden-Word Guess

Flexport logoFlexport● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This came from a real Flexport onsite interview report. The original report shared the hidden-word task, positional match scoring, and the goal of reducing guess calls. Estimated match rate: 85-90% for the core task, 55-65% for interface and examples, and 35-45% for exact original wording. If a fuller version appears later, we will update this.

A hidden target word is guaranteed to be one of the unique strings in words. Every word has the same length.

For two words a and b, their match score is the number of indices i for which a[i] == b[i]. For example, the score between aabbcc and abcdef is 1.

You have already made the guesses in guesses. The corresponding value scores[i] is the match score returned for guesses[i] against the hidden target.

First, keep only the words that are consistent with every previous guess and score. These are the remaining candidates.

Minimax selection

Choose the next guess from the remaining candidates using this rule:

  1. For a possible guess, group every remaining target candidate by the score it would return.
  2. Measure the guess by the size of its largest group.
  3. Choose the guess whose largest group is as small as possible.
  4. If several guesses tie, return the lexicographically smallest one.

Return the chosen next guess.

Notes

The target is in the supplied word list, guesses must come from that list, and feedback counts positions where both the character and index match. The goal is to identify the target with as few calls as possible; an entropy-style heuristic is a common alternative, but this problem uses the minimax rule above.

Function

chooseNextWordGuess(words: String[], guesses: String[], scores: int[]) → String

Examples

Example 1

words = ["acckzz","ccbazz","eiowzz","abcczz"]guesses = []scores = []return = "acckzz"

Using acckzz would produce scores 6, 3, 2, and 4 for the four possible targets. Every score group has size 1, so its worst group is smaller than that of any other candidate.

Example 2

words = ["acckzz","ccbazz","eiowzz","abcczz"]guesses = ["acckzz"]scores = [3]return = "ccbazz"

Among the listed words, only ccbazz has exactly three positional matches with acckzz. It is therefore the only remaining target candidate and must be returned.

Example 3

words = ["aaaa","aaab","aaba","abaa","baaa"]guesses = []scores = []return = "aaab"

Guessing aaaa puts the other four words into one score-3 group, so its worst group has size 4. Each of the other four guesses has a worst group of size 3; aaab is lexicographically smallest among them.

Constraints

  • 1 <= words.length <= 500
  • 1 <= words[i].length <= 20
  • All strings in words are unique, contain only lowercase English letters, and have equal length.
  • 0 <= guesses.length == scores.length < words.length
  • Every value in guesses appears in words.
  • 0 <= scores[i] < words[i].length, so the target has not already been found.
  • At least one word is consistent with all previous guesses and scores.

More Flexport interview questions

  • Container Ledger with TradesONSITE INTERVIEW · Seen Nov 2026
  • Apply Operations to Make a String EmptyPHONE SCREEN · Seen Nov 2026
  • Max Area of Island Without Changing the GridPHONE SCREEN · Seen Nov 2026
  • Count Good SubsequencesOA · Seen Jun 2024
  • Distinct MovesOA · Seen Jun 2024
  • Hotspot ConnectionsOA · Seen Jun 2024
  • Throw The BallOA · Seen Jun 2024
  • Matrix TraversalOA · Seen Feb 2024
  • Collect PointsOA · Seen Feb 2024
  • Malware SpreadOA · Seen Feb 2024

Similar questions at other companies

  • Choose the Next Hidden-Word GuessCharacter.AI · PHONE SCREEN
  • Invoice / Payment ReconciliationStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
  • Feature Flags with Rules, Dependencies and ExposurePerplexity AI · ONSITE INTERVIEWPerplexity AI interview questions
  • Rearrange a String So No Neighbors MatchThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
  • Reorganize a StringAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Generate Word Guess FeedbackAtlassian · ONSITE INTERVIEWAtlassian interview questions
  • Longest-Match Tokenizer with Unknown SymbolsAnthropic · ONSITE INTERVIEWAnthropic interview questions

Flexport interview experiences

  • Flexport interviews · 2026
All Flexport interview questionsSee Flexport hiring insights
Saved
class Solution {
    public String chooseNextWordGuess(String[] words, String[] guesses, int[] scores) {
      // write your code here
    }

}
Checking account…