Bloomberg Interview Question: Implement Wordle Feedback

11 Views
No Comments
// Wordle

// Random 5 letter word
// Guess the word in 6 tries or less

// Example
// Target word: "staff"
// User Guess1: "world"
// Feedback 1: "-----"

// User Guess2: "worms"
// Feedback 2: "----%"

// User Guess3: "fluff"
// Feedback 3: "---**"

// User Guess4: "staff"
// Feedback 4: "*****"

// - : wrong letter
// % : correct letter, wrong position
// * : correct letter, correct position

You must implement the feedback mechanism of the Wordle game:
Given a target 5-letter word and a user guess, return a 5-character feedback string where:

  • * means the guessed letter is in the correct position.
  • % means the letter exists in the target word but in another position.
  • - means the letter is not in the target at all.

A correct solution must also properly handle duplicate letters (e.g.,“staff”,“fluff”).

END
 0