Generate Per-Position Guess Feedback
Company: Tesla
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Take-home Project
Quick Answer: This question evaluates string-processing skills, array manipulation, and handling of duplicate character counts to produce per-position feedback. It is commonly asked to assess implementation of matching logic and edge-case management in Coding & Algorithms (string/array algorithms), and is primarily a practical application problem that also requires conceptual understanding of counting and match ordering.
Constraints
- 0 <= len(target) == len(guess) <= 200000
- Both strings contain only lowercase English letters
Examples
Input: ("sabby", "assby")
Expected Output: [1, 1, 0, 2, 2]
Explanation: Positions 3 and 4 are exact matches. Among the remaining target characters, one 'a', one 's', and one 'b' are available. The first two guess characters consume 'a' and 's', but the third 's' has no remaining match.
Input: ("apple", "apple")
Expected Output: [2, 2, 2, 2, 2]
Explanation: Every character matches in the correct position.
Input: ("abbc", "bbba")
Expected Output: [0, 2, 2, 1]
Explanation: Positions 1 and 2 are exact matches. After that, only 'a' and 'c' remain unmatched in the target, so the first 'b' gets 0 and the final 'a' gets 1.
Input: ("aab", "baa")
Expected Output: [1, 2, 1]
Explanation: The middle 'a' is an exact match. The remaining unmatched target characters are one 'a' and one 'b', so the first and last guess characters both get partial matches.
Input: ("aabc", "ddaa")
Expected Output: [0, 0, 1, 1]
Explanation: There are no exact matches. Only two 'a' characters are available for partial matching, so the last two positions get 1 and both 'd' characters get 0.
Input: ("", "")
Expected Output: []
Explanation: Empty strings produce an empty feedback array.
Hints
- Mark exact matches first. If you try to count partial matches before exact ones, duplicate characters can be overcounted.
- Store the counts of unmatched characters from `target` in a frequency array or hash map, then scan the unmatched positions in `guess`.