Word-Guessing Game Session
Problem statement
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 <= 200 <= guesses.length <= 301 <= maxAttempts <= 20- The secret and every guess contain only lowercase English letters.
- Every guess has the same length as the secret.