FastPrepNext Consistent Wordle Guess

Next Consistent Wordle Guess

Retool logoRetool● MediumFULLTIMENEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

All supplied uppercase words have equal length and distinct letters. Given a previous guess and its G, Y, and _ feedback, return the lexicographically smallest different dictionary word that could be the answer.

A candidate is consistent when comparing it as the answer against previousGuess produces exactly the supplied feedback. Return the empty string if no different candidate is consistent.

Function

nextWordleGuess(previousGuess: String, feedback: String, words: String[]) → String

Examples

Example 1

previousGuess = "ABCD"feedback = "GYY_"words = ["ACBE","AEBC","AXYZ","ABCD"]return = "ACBE"

ACBE and AEBC are consistent; ACBE is lexicographically smaller.

Example 2

previousGuess = "PHONE"feedback = "YY___"words = ["HPABC","APBHC","PHONE"]return = "APBHC"

Both nonvisited words relocate P and H; APBHC sorts first.

Example 3

previousGuess = "ABC"feedback = "GGG"words = ["ABC","ABD"]return = ""

The only consistent word is the excluded prior guess.

Constraints

  • 1 <= words.length <= 100000.
  • 1 <= previousGuess.length == feedback.length <= 26.
  • All words and the previous guess contain distinct uppercase letters and have the feedback length.
  • Feedback contains only G, Y, and _.

More Retool problems

See Retool hiring insights
public String nextWordleGuess(String previousGuess, String feedback, String[] words) {
    // write your code here
}
previousGuess"ABCD"
feedback"GYY_"
words["ACBE","AEBC","AXYZ","ABCD"]
expected"ACBE"
Checking account…