Katkat

Generate Color Feedback for a Word Guess

NgrokSoftware Engineer · Technical Screen

Last updated

Generate green, yellow, or red feedback for each character in a word guess based on positional equality and presence anywhere in the answer. Follow the stated presence semantics, where misplaced duplicate letters remain yellow rather than consuming a limited match count.

Generate Color Feedback for a Word Guess

Given an answer string and a guess of the same length, produce one color for each guessed character:

  • "green" if the character matches the answer at the same position.
  • "yellow" if it does not match at that position but appears anywhere in the answer.
  • "red" if it does not appear anywhere in the answer.

Return the colors in guess order.

Function Signature

def color_guess(answer: str, guess: str) -> list[str]:
 ...

Constraints

  • 1 <= len(answer) == len(guess) <= 100_000
  • Inputs contain lowercase English letters.
  • This task uses simple presence semantics: yellow matches are not consumed. If a letter appears anywhere in the answer, every misplaced occurrence of that letter in the guess is yellow.

Examples

Input: answer = "candy", guess = "dandy"
Output: ["yellow", "green", "green", "green", "green"]

Input: answer = "candy", guess = "zandy"
Output: ["red", "green", "green", "green", "green"]

Input: answer = "aba", guess = "bbb"
Output: ["yellow", "green", "yellow"]

Clarifications

  • Check positional equality before checking whether a character appears elsewhere.
  • The duplicate-letter rule intentionally differs from count-limited Wordle scoring.