Return dictionary words matching a prefix
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This problem evaluates string-processing and filtering skills, focusing on exact prefix matching, case sensitivity, duplicate handling, and edge-case management over arrays of strings. Commonly asked in Coding & Algorithms interviews, it assesses practical implementation ability and understanding of algorithmic complexity at an implementation-level (basic to intermediate).
Constraints
- 0 <= len(words) <= 100000
- 0 <= len(prefix) <= 1000
- Each element of `words` is a string
- Matching must be case-sensitive
Examples
Input: (['apple', 'app', 'banana', 'apply'], 'app')
Expected Output: ['apple', 'app', 'apply']
Explanation: These are the words that start with 'app', kept in their original order.
Input: (['Cat', 'car', 'Cart', 'dog'], 'Ca')
Expected Output: ['Cat', 'Cart']
Explanation: Matching is case-sensitive, so 'car' does not match 'Ca'.
Input: (['dog', 'deer'], 'cat')
Expected Output: []
Explanation: No word starts with 'cat'.
Input: (['test', 'team', 'test', 'toast'], 'te')
Expected Output: ['test', 'team', 'test']
Explanation: Duplicates are preserved in the result.
Input: ([], 'a')
Expected Output: []
Explanation: An empty dictionary has no matches.