Skip to content
QuizMaker logoQuizMaker
Activity
DSA Interview Patterns Roadmap

No lessons available

CONTENTS

Google Wordle Color String

Turn the Google Wordle Color String interview variant into a clear brute-force baseline, optimized pattern, and implementation plan.

DSA Interview Patterns Roadmap
Company Asked Variants
dsa
coding interview
+5
May 29, 2026
20
A

Learning Outcome

Turn the Google Wordle Color String interview variant into a clear brute-force baseline, optimized pattern, and implementation plan.

Original Interview Statement

Given secret and guess of equal length, return b/y/g feedback with one secret character used at most once.

Examples

ItemDetail
secret = acdz, guess = cxdzybgg

Brute Force Approach

For every guess character, search secret for an unused same character. This is O(n^2) and easy to get wrong with duplicates.

Optimized Approach

First mark greens, then count remaining secret letters. Use those counts to assign yellows exactly once.

Exact Pseudocode

mark all greens
count non-green secret chars
for each non-green guess char:
  if count exists: mark yellow and decrement
  else mark black

Reference Code

from collections import Counter

def color(secret, guess):
    n = len(secret)
    ans = ['b'] * n
    left = Counter()
    for i in range(n):
        if guess[i] == secret[i]:
            ans[i] = 'g'
        else:
            left[secret[i]] += 1
    for i in range(n):
        if ans[i] == 'g':
            continue
        if left[guess[i]] > 0:
            ans[i] = 'y'
            left[guess[i]] -= 1
    return ''.join(ans)

Complexity

ItemDetail
Brute forceO(n^2)
OptimizedO(n + alphabet) time, O(alphabet) space

Edge Cases

  • Duplicate letters
  • All greens
  • No matches
  • Guess char appears as green elsewhere

Follow-ups

  • Support Unicode letters
  • Return counts of each color

Nearest Practice References

  • Wordle
  • Bulls and Cows

Common Mistakes

  • Copying the nearest LeetCode solution without checking the changed rule.
  • Skipping duplicate or boundary cases.
  • Not stating the brute force before the optimized approach.

Share this article

Test your knowledge

Take a quick quiz based on this chapter.

hardDSA Interview Patterns
Quiz: Google Wordle Color String
6 questions10 min

0 comments

Please login to comment.
No comments yet.
Lesson 3 of 13 in Company Asked Variants
Previous in Company Asked Variants
Myntra Non-perfect-square Pairs
Next in Company Asked Variants
Google Wordle Feedback Validation
Back to DSA Interview Patterns Roadmap
Back to moduleCategories