Wordle Guess Loop
Reported by candidates from Retool's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Retool reportedly asked this one in June 2024, and the input size is what decides how you write it. With up to 2000 words, each at most 26 letters, you can't do anything clever or wasteful per step. It's a simulation problem wearing a Wordle costume. You guess, compute G/Y/_ feedback against the answer, then pick the smallest unvisited word that would give the same feedback. If you're staring at the invite and wondering whether there's a hidden trick, there isn't a big one. It's careful bookkeeping. StealthCoder sits invisibly as a safety net during the live OA if the feedback logic tangles on you.
The problem
Every supplied uppercase word has the same length and contains no repeated letters. Start with start and repeatedly make Wordle guesses until you reach answer. After each wrong guess, compute G, Y, and _ feedback against the answer. Choose the lexicographically smallest unvisited dictionary word that would produce exactly that feedback if it were the answer. Remove each chosen word from future consideration. Return the number of guesses including the starting guess, or -1 if no unvisited consistent word remains. Function countWordleGuesses(words: String[], start: String, answer: String) → int Examples Example 1 words = ["ABCD","ACBE","AEBC"] start = "ABCD" answer = "AEBC" return = 3 Feedback GYY_ first selects ACBE, then the next feedback selects AEBC. Example 2 words = ["PHONE","HPABC","APBHC"] start = "PHONE" answer = "APBHC" return = 2 APBHC is the smallest unvisited word matching the observed feedback. Example 3 words = ["START"] start = "START" answer = "START" return = 1 The starting word is already the answer. Constraints 1 <= words.length <= 2000. 1 <= words[i].length == start.length == answer.length <= 26. Every word contains distinct uppercase English letters. answer occurs in words.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The constraint is small enough that brute force per guess is fine. Sort the words once so lexicographic order comes free. Then loop: if the current guess equals the answer, return the count. Otherwise compute feedback of guess vs answer. Scan the sorted list, skip visited words, and for each candidate compute feedback of guess vs candidate. The first one whose feedback matches exactly is the next guess. Mark it visited. If none match, return -1. Each step costs about 2000 words times 26 letters, and there are at most 2000 steps, so roughly 100 million simple operations worst case. That's acceptable. Because letters are distinct, feedback is easy: G if same position, Y if the letter appears elsewhere, else underscore. No duplicate-letter rules to handle. The pitfall is mixing up which word is the answer in the consistency check. Candidate plays the answer role, the guess stays the guess. StealthCoder is the hedge if you blank on that direction during the live OA.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Wordle Guess Loop 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Retool's OA.
Retool reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Wordle Guess Loop FAQ
How hard is the Retool Wordle Guess Loop really?+
Easy to medium. There's no fancy algorithm. The difficulty is reading the statement correctly and getting the feedback function right. Distinct letters remove the nasty duplicate-letter Wordle cases, so most of the risk is in the consistency check, not the logic.
What's the trick to the feedback check?+
Compute feedback(guess, candidate) and compare it to feedback(guess, answer). If they're identical strings, the candidate is consistent. Don't compare candidate to answer directly. The feedback is always relative to the current guess.
Do I need anything faster than brute force?+
No. With 2000 words and length at most 26, scanning the whole sorted list per guess is fine. Sort once up front, keep a visited array, and take the first match. Worst case is around 100 million simple operations, which is acceptable.
When should I return -1?+
Return -1 when you've made a wrong guess and the scan finds no unvisited word with matching feedback. Note that the answer itself is always consistent unless it was already visited, so -1 only happens when it's been consumed earlier.
How do I prepare for this in 48 hours?+
Practice writing a clean feedback function and a sorted scan with a visited set. Test the three examples by hand, plus the case where start equals answer. Count the starting guess as 1. Most bugs are off-by-one on the guess count.