Article start
DSA Interview Patterns Roadmap
Company Asked Variants

Google Wordle Color String

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

May 29, 2026·21

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.

Discussion

0 comments

Sign in to share a question or add to the discussion.
Start the discussion

Ask a question or share what stood out to you.