Words Matching Guess Feedback
MediumStrings ยท Ramp
Given distinct lowercase words of equal length and a list of past rounds, each [guess, feedback], return the words that could be the hidden target, in their original order. A word qualifies if scoring every guess against it gives exactly the recorded feedback.
Scoring a guess against a target gives one letter per position:
Gif the guess letter equals the target letter at that position.Yif it is notGand the target still has an unused copy of that letter. Copies atGpositions are used first, then the other guess positions claim copies from left to right.Botherwise.
Example 1
- Input:
- words = ["crate", "crave", "grace", "brace", "trace"], rounds = [["crane", "YGGBG"], ["grave", "BGGBG"]]
- Output:
- ["brace", "trace"]
- Explanation
- Against
crane,grace,braceandtraceall scoreYGGBG. Againstgrave,gracescoresGGGBG, so it is dropped.
Example 2
- Input:
- words = ["hello", "world", "allow", "jelly", "cello"], rounds = [["llama", "YYBBB"]]
- Output:
- ["hello", "jelly", "cello"]
- Explanation
worldhas onel, sollamawould scoreYBBBBagainst it.
Example 3
- Input:
- words = ["ab", "ba"], rounds = []
- Output:
- ["ab", "ba"]
Constraints
0 <= words.length <= 20001 <= words[i].length <= 10, and every word and guess has the same length0 <= rounds.length <= 20feedbackhas the same length asguessand uses onlyG,YandB