Resolve Abbreviated CLI Commands Against A Command Tree
Last updated: November 29, 2026
Quick Overview
Network OS command lines accept unique prefixes, so 'sh ip int br' means 'show ip interface brief'. Given a nested command tree and a list of typed tokens, return the fully expanded command or an error that says whether a token was ambiguous, invalid, or unexpected.
Cisco
November 29, 20260
0
0 solved
Network OS command lines accept unique prefixes, so 'sh ip int br' means 'show ip interface brief'. Given a nested command tree and a list of typed tokens, return the fully expanded command or an error that says whether a token was ambiguous, invalid, or unexpected.
The IOS-style parser is something every Cisco network OS engineer touches, and abbreviation matching is its most visible behavior. The interviewer checks that you model the tree cleanly, prefer an exact keyword match over prefix matches, and produce useful error messages.
What the Interviewer Expects
- Models the commands as a nested dict or trie
- Walks one level per token
- Treats an exact keyword match as winning even if it is also a prefix of another keyword
- Distinguishes ambiguous, invalid, and too-many-token errors
- Is case-insensitive
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 support '?' to list the valid completions at the current level?
- How would you handle argument tokens like interface names or IP addresses that are not keywords?
- How do you keep lookup fast when a level has hundreds of keywords?
- How would you report the error position with a caret like the real CLI?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: tokens such as ['sh', 'ip', 'int', 'br'] and a tree where each keyword maps to a child dict, or None for a leaf. Output: ('ok', 'show ip interface brief') or ('error', message). A token...
High-Level Design
Walk the tree level by level. At each level, check for an exact match first (so a keyword like ip is not ambiguous with ipv6). Otherwise, collect keywords starting with the token. Zero matches is ...