Reported July 2024
Character.AIstring

Choose the Next Hidden-Word Guess

Reported by candidates from Character.AI's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Character.AI OA. Under 2s to a working solution.
Founder's read

Character.AI reported this one in July 2024, and the detail that trips people is the three-line rule buried in the statement: pick the guess whose biggest score group is smallest, then break ties alphabetically. It's a word-guessing game, but the code is plain string filtering plus a minimax count. You've got a 500-word cap and 20-character words, so brute force is fair game. If you blank on the structure during the live OA, StealthCoder sits invisible on your screen as a safety net and hands you the filter-then-score skeleton.

The problem

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:
For a possible guess, group every remaining target candidate by the score it would return.
Measure the guess by the size of its largest group.
Choose the guess whose largest group is as small as possible.
If several guesses tie, return the lexicographically smallest one.
Return the chosen next guess.
What the interview report shared
The report described an onsite word-guessing variant. 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, and the report mentioned an entropy-style idea. It did not provide an exact function signature, constraints, or tie-breaking rule.

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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Two phases. First, filter: keep each word w where, for every previous guess g[i], the positional match count between w and g[i] equals scores[i]. Second, minimax: for each remaining candidate as a guess, loop over all remaining candidates, compute the match score, bucket in a count array sized word length plus one, and track the max bucket. Pick the smallest max, and on ties the lexicographically smallest word. Cost is roughly n squared times L, about 5 million operations at the limits, which is fine. The pitfall is the tie-break. Example 3 shows it: four guesses tie at 3, and aaab wins. Another trap is the self-match, since a guess scores full length against itself and sits in its own bucket. Keep it in, as Example 1 does. StealthCoder is your hedge if the bucket logic slips under time pressure.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Choose the Next Hidden-Word Guess cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as guess the word. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Character.AI's OA.

Character.AI reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Choose the Next Hidden-Word Guess FAQ

How hard is the Character.AI next-guess problem really?+

Easier than it reads. It's a medium at most. The statement is long, but the algorithm is filter, count, compare. With 500 words and 20 characters, an O(n squared times L) solution runs comfortably. The difficulty is reading carefully, not clever algorithms.

What's the trick to the minimax selection?+

For each remaining candidate, bucket every other candidate by positional match score and take the largest bucket size. Choose the candidate with the smallest largest-bucket. Ties go to the lexicographically smallest string. Nothing fancier is needed, and no entropy calculation is required.

Should the guess pool be all words or only remaining candidates?+

Only the remaining candidates, per the stated rule. Filter first using every guess and score pair, then evaluate guesses from that filtered set. Using the full list would break Example 2, where only one candidate is left and must be returned.

Does the entropy idea from the report matter?+

No. The report mentioned an entropy-style idea, but the problem as written defines the criterion as the smallest worst-case group. Implement exactly that. Entropy would give different answers on ties and fail the examples.

How do I prepare for this in 48 hours?+

Write the match-score helper, the filter loop, and the bucket-and-compare loop from scratch once. Then test Example 3 by hand, especially the tie-break among aaab, aaba, abaa, and baaa. That covers every edge this problem has.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Character.AI.

OA at Character.AI?
Invisible during screen share
Get it