FastPrepDeterministic Word Guess Solver

Deterministic Word Guess Solver

Atlassian logoAtlassian● HardFULLTIMEONSITE INTERVIEW

Problem statement

You are given an ordered list of distinct five-letter potentialSecrets, the actual secret, and a guess limit.

On each turn, guess the first candidate still consistent with every previous feedback result. Generate feedback using G, Y, and X with exact matches consuming letter copies before misplaced matches. After a non-winning guess, keep a candidate only when that candidate would produce exactly the observed feedback for the same guess.

Return the guesses in order, stopping after guessing the secret or after maxAttempts guesses.

Function

solveWord(potentialSecrets: String[], secret: String, maxAttempts: int) → String[]

Examples

Example 1

potentialSecrets = ["cigar","rebut","sissy"]secret = "sissy"maxAttempts = 5return = ["cigar","sissy"]

The first feedback eliminates every candidate except sissy.

Example 2

potentialSecrets = ["apple","angle","amble"]secret = "amble"maxAttempts = 3return = ["apple","angle","amble"]

The first two guesses share the same pattern against the remaining possibilities, so deterministic order reaches amble third.

Constraints

  • 1 <= potentialSecrets.length <= 2000
  • Every candidate has length 5.
  • secret.length == 5
  • 1 <= maxAttempts <= 20
  • All words contain only lowercase English letters, candidates are distinct, and secret appears in potentialSecrets.

More Atlassian problems

See Atlassian hiring insights
Saved
public String[] solveWord(String[] potentialSecrets, String secret, int maxAttempts) {
    // Write your code here.
}
potentialSecrets["cigar","rebut","sissy"]
secret"sissy"
maxAttempts5
expected["cigar", "sissy"]
Checking account…