FastPrepWord-Guessing Game Session
Problems/Word-Guessing Game Session

Word-Guessing Game Session

Shopify logoShopify● MediumINTERNPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes a multistep OOP word-guessing game but does not give its rules. This round-based letter-feedback exercise matches that reported idea at about 35%; feedback, attempt limits, statuses and examples are practice assumptions.

Implement a word-guessing game that owns one round's secret, attempt count, and status. Process the guesses in order and return the result of each guess.

For this exercise, assume the following letter-feedback rules:

  • G: the guessed letter is correct at this position.
  • Y: it is in the secret at another position and an unmatched copy remains.
  • B: no unmatched copy remains.

For this exercise, assume exact matches are assigned first. Count the remaining secret letters, then assign Y or B from left to right, consuming one copy for each Y.

For this exercise, assume every active guess uses one attempt. A correct guess changes the status to WON, even on the last allowed attempt. Otherwise, reaching maxAttempts changes it to LOST; before that, it is PLAYING. Once the round ends, later guesses are ignored.

Return each active result as feedback:status, such as GYBBB:PLAYING. For an ignored guess, return IGNORED:WON or IGNORED:LOST. Start a fresh round for each call.

Function

playWordGame(secret: String, guesses: String[], maxAttempts: int) → String[]

Examples

Example 1

secret = "apple"guesses = ["allee","apple","apple"]maxAttempts = 3return = ["GYBBG:PLAYING","GGGGG:WON","IGNORED:WON"]

For allee, the first a and final e are exact matches. One unmatched l makes the first guessed l yellow; the extra l and e are black. The next guess wins, so the final guess is ignored.

Example 2

secret = "cat"guesses = ["dog","cat"]maxAttempts = 1return = ["BBB:LOST","IGNORED:LOST"]

dog shares no letters with cat. It uses the only attempt, ending the round as LOST. The later correct guess is ignored.

Constraints

  • 1 <= secret.length <= 20
  • 0 <= guesses.length <= 30
  • 1 <= maxAttempts <= 20
  • The secret and every guess contain only lowercase English letters.
  • Every guess has the same length as the secret.

More Shopify problems

  • Deterministic Secret Santa AssignmentPHONE SCREEN · Seen Oct 2026
  • Mars Rover Robot ControllerPHONE SCREEN · Seen Oct 2026
  • Choose Items for a BackpackOA · Seen May 2026
All Shopify interview questionsSee Shopify hiring insights
Saved
public String[] playWordGame(String secret, String[] guesses, int maxAttempts) {
    // Create a game round and return one result per guess.
}
Checking account…