FastPrepGenerate Word Guess Feedback

Generate Word Guess Feedback

Atlassian logoAtlassian● MediumFULLTIMEONSITE INTERVIEW

Problem statement

Given a five-letter guess and five-letter secret, return a five-character feedback string.

  • G: the letter is correct and in the correct position.
  • Y: the letter is present in another position.
  • X: the letter is absent after accounting for already matched copies.

Each copy of a secret letter may satisfy at most one guess position. Exact matches take priority over misplaced matches.

Function

generateFeedback(guess: String, secret: String) → String

Examples

Example 1

guess = "allee"secret = "apple"return = "GYXXG"

The first a and final e are exact; only one l is available as a misplaced match.

Example 2

guess = "civic"secret = "vivid"return = "XGGGX"

The middle three letters match exactly and neither c appears in the secret.

Constraints

  • guess.length == 5
  • secret.length == 5
  • Both strings contain only lowercase English letters.

More Atlassian problems

See Atlassian hiring insights
Saved
public String generateFeedback(String guess, String secret) {
    // Write your code here.
}
guess"allee"
secret"apple"
expected"GYXXG"
Checking account…