Word Guess Feedback Colors
Updated
Problem statement
Compare a five-letter guess with a five-letter secret, and return five feedback characters in guess order. The first argument is the secret; the second is the guess.
G(green): the letter is correct at this position.Y(yellow): the letter exists in another unmatched position of the secret.X(gray): no unmatched copy remains in the secret.
For this exercise, assume exact matches are assigned first. Then process the other guess positions from left to right, using each remaining secret letter at most once. This defines feedback when letters repeat.
Complete wordGuessFeedback(secret, guess). The function name is the practice interface; the feedback rules and argument order above also apply to a function named generateFeedback.
Follow-up: Keep this feedback function reusable by a solver that filters possible secrets after each guess and always chooses the first remaining word.
Function
wordGuessFeedback(secret: String, guess: String) → StringExamples
Example 1
secret = "house"guess = "stole"return = "YXYXG"The guess letters are s, t, o, l, e. The s and o occur elsewhere in house, t and l are absent, and e matches position 5. The feedback is YXYXG.
Example 2
secret = "crane"guess = "plane"return = "XXGGG"The p and l in the guess are absent from crane. The a, n and e match positions 3, 4 and 5, giving XXGGG.
Example 3
secret = "crane"guess = "mould"return = "XXXXX"None of m, o, u, l or d occurs in crane, so every position is X.
Example 4
secret = "apple"guess = "allee"return = "GYXXG"The first a and last e are exact matches. One remaining l gives Y at position 2. No second l or unmatched e remains, so positions 3 and 4 are X.
Constraints
secret.length == 5andguess.length == 5.- Both strings contain only lowercase English letters.
More Atlassian interview questions
- Merge Overlapping IntervalsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Tennis Court SchedulingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Deterministic Word Guess SolverONSITE INTERVIEW · Seen Oct 2026
- Generate Word Guess FeedbackONSITE INTERVIEW · Seen Oct 2026
- Bounded Word Guess SolverONSITE INTERVIEW · Seen Oct 2026
- Implement a Rate LimiterPHONE SCREEN · Seen Oct 2026
- Longest Consistent Activity StreakPHONE SCREEN · Seen Sep 2026
- Music Player Operation SequencePHONE SCREEN · Seen Sep 2026
- Underline Shortest Unique SubstringsPHONE SCREEN · Seen Aug 2026
- Can a Dictionary Word Be Formed from Note Letters?PHONE SCREEN · Seen Feb 2026
Similar questions at other companies
- Feature Flags with Rules, Dependencies and ExposurePerplexity AI · ONSITE INTERVIEWPerplexity AI interview questions
- Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Invoice / Payment ReconciliationStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
- In-Memory Vault File SystemHarvey · ONSITE INTERVIEWHarvey interview questions
- Stable Unique Column RenamesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Most Frequent Call Path in Interleaved LogsRoblox · ONSITE INTERVIEWRoblox interview questions
- Dictionary Records to an Editable XML TreeSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
- Choose the Next Hidden-Word GuessFlexport · ONSITE INTERVIEWFlexport interview questions
- In-Memory Directory and File OperationsSquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions