← Questions
Per-position feedback for a guess against a secret word
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Tesla's second technical round, last asked May 2026. It tests strings, hash maps and simulation.
Score a guess against a secret word, as in Wordle. Both words have the same length. For each position of the guess, return one mark:
-
G— the letter is in the secret at this position. -
Y— the letter is in the secret but at a different position. -
B— the letter is not in the secret, or every copy of it in the secret is already used by other marks.
Repeated letters must be counted correctly: a letter is marked G or Y at most as many times as it appears in the secret, and exact matches take priority.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
feedback(secret: str, guess: str) -> str— returns a string ofG,YandB, one per position.
Example
feedback("apple", "paper") -> "YYGYB"
feedback("crane", "eerie") -> "BBYBG" # the last e is exact; crane has one e, so the first two e's get B
feedback("speed", "erase") -> "YBBYY" # speed has two e's, so both e's in the guess get Y
Constraints
-
secretandguesshave the same length and hold lowercase letters only.
Clarifying questions
- When a letter appears more times in the guess than in the secret, which copies get
Y? (Usual rule: left to right, after exact matches.) - Is the input always the same length and lowercase?
- Must the guess be a valid word from a dictionary?
What a strong answer covers
- Two passes: first mark exact matches and count the secret's unmatched letters; then, left to right, give
Ywhile that letter's count is positive and decrement it. - Why a single pass gets repeated letters wrong (a
Ycan steal the copy a laterGneeds). - O(n) time, O(alphabet) space.
- Tests with repeated letters in the guess, in the secret, and in both.
Follow-ups
- Given a list of past guesses and their feedback, filter a word list to the words still possible.
- Pick the next guess that best splits the remaining candidates.
- Support Unicode letters or case-insensitive matching.
Where it's asked
- Tesla · Second technical round · Last asked May 202645 min · Coding, often combined with team fit
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
