FastPrepBounded Word Guess Solver

Bounded Word Guess Solver

Atlassian logoAtlassian● EasyFULLTIMEONSITE INTERVIEW
Learn

Problem statement

A solver has an ordered list of planned guesses and may make at most maxGuesses attempts. Return whether the secret word appears among the guesses the solver is allowed to make.

Stop after the first min(maxGuesses, guesses.length) entries. Repeated guesses still consume attempts.

Function

canSolveWithinGuesses(secret: String, guesses: String[], maxGuesses: int) → boolean

Examples

Example 1

secret = "APPLE"guesses = ["CRANE","APPLE"]maxGuesses = 2return = true

Only guesses inside the allowed prefix are considered.

Example 2

secret = "APPLE"guesses = ["CRANE","APPLE"]maxGuesses = 1return = false

Only guesses inside the allowed prefix are considered.

Example 3

secret = "A"guesses = ["A"]maxGuesses = 0return = false

Only guesses inside the allowed prefix are considered.

Constraints

  • 1 <= secret.length <= 100.
  • 0 <= guesses.length <= 100000.
  • Every guess has the same length as secret.
  • 0 <= maxGuesses <= 100000.

More Atlassian problems

See Atlassian hiring insights
public boolean canSolveWithinGuesses(String secret, String[] guesses, int maxGuesses) {
    // Write your code here.
}
secret"APPLE"
guesses["CRANE","APPLE"]
maxGuesses2
expectedtrue
Checking account…