FastPrepWord Guess Feedback Colors

Word Guess Feedback Colors

Atlassian logoAtlassian● MediumFULLTIMEONSITE INTERVIEW
Learn

Problem statement

Given equal-length uppercase strings answer and guess, return one result character per guess position.

  • G: the character matches the answer at this position.
  • Y: after exact matches are consumed, another unmatched copy of this character exists elsewhere in the answer.
  • R: no unmatched copy remains.

Each answer character may be matched at most once.

Function

wordGuessFeedback(answer: String, guess: String) → String

Examples

Example 1

answer = "APPLE"guess = "ALLEY"return = "GYRYR"

The two-pass rule consumes exact matches before assigning remaining copies.

Example 2

answer = "CRANE"guess = "CRANE"return = "GGGGG"

The two-pass rule consumes exact matches before assigning remaining copies.

Example 3

answer = "ABCDE"guess = "FGHIJ"return = "RRRRR"

The two-pass rule consumes exact matches before assigning remaining copies.

Constraints

  • 1 <= answer.length == guess.length <= 1000.
  • Both strings contain uppercase English letters.

More Atlassian problems

See Atlassian hiring insights
public String wordGuessFeedback(String answer, String guess) {
    // Write your code here.
}
answer"APPLE"
guess"ALLEY"
expected"GYRYR"
Checking account…