Ranked Tab Completion for MATLAB Function Names
Last updated: November 29, 2026
Quick Overview
Build a completer that records how often each function name is used and, given a typed prefix, returns the top k matching names by usage count, breaking ties alphabetically.
MathWorks
November 29, 20260
0
0 solved
Build a completer that records how often each function name is used and, given a typed prefix, returns the top k matching names by usage count, breaking ties alphabetically.
The MATLAB Desktop and MATLAB Online editor offer tab completion over thousands of functions across installed toolboxes. MathWorks interviewers use this to test trie design, ranking, and the trade-off between query-time search and precomputed top-k lists at each node.
What the Interviewer Expects
- Uses a trie so the prefix walk costs O(length of prefix)
- Stores usage count at terminal nodes and supports repeated recording
- Collects candidates under the prefix and selects top k with a heap
- Defines tie-breaking (alphabetical) and returns [] for unknown prefixes
- Discusses caching top k per node for faster queries at the cost of updates
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you keep a precomputed top-k list at every node and update it when counts change?
- How would you add fuzzy matching so 'plto' still suggests 'plot'?
- Completion must respect the current MATLAB path and shadowed functions. Where does that filter go?
- How would you rank by a mix of global popularity and this user's history?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Operations: record(name, times=1) adds usage; suggest(prefix, k=3) returns up to k names that start with the prefix, highest count first, ties broken alphabetically. Names are case-sensitive, as M...
High-Level Design
Each trie node has a child map, an end flag and a count. record walks or creates nodes and bumps the count at the end node. suggest walks the prefix; if it falls off the trie, return []. Otherwi...