You are implementing feedback for a Wordle-like guessing game.
You are given two strings of equal length guess and target (lowercase letters). For each index i, output a status character:
G
(green):
guess[i] == target[i]
Y
(yellow):
guess[i] != target[i]
, and the letter
guess[i]
occurs in
target
in some position
not already matched by a G
, respecting multiplicity (i.e., each occurrence in
target
can be used at most once across all
Y
assignments).
W
(white/gray): otherwise.
Return a string of length n over {G,Y,W}.
guess = "cable"
,
target = "maple"
→
WGWGG
guess = "paple"
,
target = "maple"
→
WGGGG
guess = "apple"
,
target = "maple"
→
YWGGG
Now the same target is used for multiple rounds. After each evaluated guess, you “learn” some letters are impossible.
A future guess is considered invalid_input if it contains any letter that was previously confirmed to be absent from target.
Clarification for repeated letters: a letter should be considered “confirmed absent” only if, in some previous round, all occurrences of that letter in that guess were marked W (i.e., the letter never appeared as G or Y in that round).
Round 1: guess = "cable", target = "maple" → WGWGG
c
,
b
.
Round 2: guess = "cazle", target = "maple" → return invalid_input (contains c, which was confirmed absent).
Implement the evaluator for Part 1 and the validator logic for Part 2.
1 <= n <= 10^5
(design an efficient solution)
guess.length == target.length