Implement trie-based autocomplete
Company: Pinterest
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
Quick Answer: This question evaluates understanding and implementation of trie data structures for prefix-based retrieval, testing competencies in string algorithms, data structures, and algorithmic time/space complexity; Category: Coding & Algorithms.
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([['insert','apple'], ['insert','app'], ['search','app'], ['startsWith','ap'], ['suggest','app',5]],)
Expected Output: [None, None, True, True, ['app', 'apple']]
Explanation: Insert/search/suggest.
Input: ([['suggest','',2], ['insert','bat'], ['insert','bar'], ['suggest','ba',1]],)
Expected Output: [[], None, None, ['bar']]
Explanation: Empty trie then limited suggestions.
Input: ([['insert','same'], ['insert','same'], ['suggest','s',3]],)
Expected Output: [None, None, ['same']]
Explanation: Duplicate insert is idempotent.
Hints
- Choose a representation that makes the requested operation direct.
- Handle empty inputs and boundary cases first.