Wordle Feedback with Duplicate Letters
Problem statement
Given two uppercase five-letter strings answer and guess, return a five-character feedback string.
2: the guessed letter matches the answer at the same position.1: after exact matches are consumed, an unmatched copy of the guessed letter exists at another position.0: no unmatched copy exists.
Consume exact matches first so repeated letters are never counted more times than they occur in answer.
Function
wordleFeedback(answer: String, guess: String) → StringExamples
Example 1
answer = "SPACE"guess = "APPLE"return = "12002"The first P is exact; the second P cannot reuse that same answer occurrence.
Example 2
answer = "LEVEL"guess = "HELLO"return = "02110"The E is exact; the two guessed Ls consume the two unmatched Ls in the answer.
Example 3
answer = "CRANE"guess = "CRANE"return = "22222"Every position matches exactly.
Constraints
answer.length == guess.length == 5.- Both words contain only uppercase English letters.