Implement WordGuess feedback scoring
Company: Verkada
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
## WordGuess (Wordle-like) scoring
Implement a function that scores a `guess` against a `secret` word of the same length.
### Scoring rules (per character)
Return an integer array `result` of length `n` (where `n = secret.length = guess.length`):
- **GREEN = 2**: `guess[i] == secret[i]` (exact match)
- **YELLOW = 1**: `guess[i] != secret[i]`, but `guess[i]` occurs **elsewhere** in `secret` **and there is still unmatched availability** of that character after accounting for GREEN matches and other YELLOW assignments (i.e., respect letter multiplicity).
- **GRAY = 0**: the character does not occur in `secret` (or all occurrences are already consumed by GREEN/YELLOW matches).
This is the same matching behavior used by Wordle: GREEN matches are applied first; then YELLOWs are assigned based on remaining character counts in the secret.
### Input validation
Throw an exception (or return an error) if any of the following are true:
- `secret` or `guess` is null/empty
- lengths differ
- inputs contain invalid characters (define and enforce a rule, e.g., only lowercase English letters `a-z`)
### Examples
1. `secret = "hello"`, `guess = "abcde"` → `result = [0,0,0,0,1]`
(`e` exists in `secret` but not at the same position)
2. `secret = "hello"`, `guess = "eabcd"` → `result = [1,0,0,0,0]`
3. Duplicate-letter behavior: `secret = "aabb"`, `guess = "bbba"` → `result = [1,2,0,1]`
Explanation: index1 is GREEN (`b`), remaining secret letters have one `b` and two `a` available, so only one of the remaining `b`s can be YELLOW.
### What to implement
Write the core scoring function (you do **not** need to build a full interactive game loop unless explicitly asked).
- **Input:** `secret: string`, `guess: string`
- **Output:** `int[] result` (values in `{0,1,2}`)
Quick Answer: This question evaluates proficiency in string processing, frequency counting, and edge-case handling by requiring implementation of Wordle-like feedback scoring for guess versus secret words.
Implement a function solution(secret, guess) that returns WordGuess/Wordle-style feedback for each position. Use 2 for GREEN (exact match), 1 for YELLOW (the guessed letter exists elsewhere in secret and still has unused availability after all GREEN matches are removed), and 0 for GRAY otherwise. Matching must respect duplicate letters, so all GREEN matches are processed first and YELLOW matches consume only the remaining available letters. Raise ValueError if secret or guess is not a string, is empty, lengths differ, or any character is outside 'a' to 'z'.
Constraints
- For valid inputs, 1 <= len(secret) == len(guess) <= 100000
- Inputs may contain only lowercase English letters 'a' to 'z'; otherwise raise ValueError