Implement Wordle feedback for a five-letter target word and a guess. Return one character for each letter in the guess, in the same order. As a follow-up, process a list of guesses with a maximum number of attempts.
G: The letter matches the target at the same position.Y: The letter matches an unused occurrence elsewhere in the target.X: No unused matching occurrence remains in the target.G matches first, then assign Y matches to the remaining guess positions from left to right. This rule also applies to repeated letters.String generateFeedback(String targetWord, String guess)
targetWord: The word to be guessed.guess: The submitted guess.G, Y, and X.List<String> generateFeedbackForAttempts(String targetWord, List<String> guesses, int maxAttempts)
targetWord: The target shared by all attempts.guesses: The guesses to process in their given order.maxAttempts: The maximum number of guesses to process.generateFeedback for each processed guess. Each guess starts with all target letter occurrences available again."GGGGG", after maxAttempts guesses, or when the list ends, whichever happens first.targetWord.length() == 5guess.length() == 5 and every entry in guesses has length 5.0 ≤ guesses.size() ≤ 10,0001 ≤ maxAttempts ≤ 10,000generateFeedback(targetWord = "plant", guess = "plate")
Output: "GGGYX"
The first three letters match their positions. The letter t belongs elsewhere in the target, while e is absent.
generateFeedback(targetWord = "abbey", guess = "bobby")
Output: "YXGXG"
The third and fifth letters are exact matches. The first b uses the remaining target b, so the fourth letter receives X. The letter o is absent.
generateFeedbackForAttempts(targetWord = "plant", guesses = ["plate", "slant", "plant", "prone"], maxAttempts = 5)
Output: ["GGGYX", "XGGGG", "GGGGG"]
The third guess finds the target, so the fourth guess is not processed.
generateFeedbackForAttempts(targetWord = "plant", guesses = ["plate", "slant", "plant", "prone"], maxAttempts = 2)
Output: ["GGGYX", "XGGGG"]
Only the first two guesses are processed because the attempt limit is reached.