Implement a function that scores a guess against a secret word of the same length.
Return an integer array result of length n (where n = secret.length = guess.length):
guess[i] == secret[i]
(exact match)
guess[i] != secret[i]
, but
guess[i]
occurs
elsewhere
in
secret
and there is still unmatched availability
of that character after accounting for GREEN matches and other YELLOW assignments (i.e., respect letter multiplicity).
secret
(or all occurrences are already consumed by GREEN/YELLOW matches).
This is the same matching behavior used by Wordle: GREEN matches are applied first; then YELLOWs are assigned based on remaining character counts in the secret.
Throw an exception (or return an error) if any of the following are true:
secret
or
guess
is null/empty
a-z
)
secret = "hello"
,
guess = "abcde"
→
result = [0,0,0,0,1]
e
exists in
secret
but not at the same position)
secret = "hello"
,
guess = "eabcd"
→
result = [1,0,0,0,0]
secret = "aabb"
,
guess = "bbba"
→
result = [1,2,0,1]
b
), remaining secret letters have one
b
and two
a
available, so only one of the remaining
b
s can be YELLOW.
Write the core scoring function (you do not need to build a full interactive game loop unless explicitly asked).
secret: string
,
guess: string
int[] result
(values in
{0,1,2}
)