FastPrepWordle Guess Loop

Wordle Guess Loop

Retool logoRetool● MediumFULLTIMENEW GRADPHONE SCREEN
Learn

Problem statement

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.

More Retool problems

See Retool hiring insights
public int countWordleGuesses(String[] words, String start, String answer) {
    // Write your code here.
}
words["ABCD","ACBE","AEBC"]
start"ABCD"
answer"AEBC"
expected3
Checking account…