Shortest Unique Prefix for Each PowerShell Command Name
Last updated: November 29, 2026
Quick Overview
Given a list of distinct command names, return for each one the shortest prefix that identifies it uniquely among the list, or the whole name if it is itself a prefix of another command.
Microsoft
November 29, 20260
0
0 solved
Given a list of distinct command names, return for each one the shortest prefix that identifies it uniquely among the list, or the whole name if it is itself a prefix of another command.
A Microsoft technical screen question tied to how PowerShell and other shells let users type abbreviated parameter or command names. The interviewer is checking that you augment a trie with pass-through counts instead of comparing every pair of strings.
What the Interviewer Expects
- Insert all names into a trie with a count of names passing through each node
- Stop at the first node whose count is 1
- Fall back to the full name when no node has count 1
- Compare to the sort-and-compare-neighbors alternative
- State complexity in total characters
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
- Solve it with sorting and comparing adjacent names instead of a trie.
- How would you update the answers incrementally when a new command is installed?
- How would case-insensitive matching change the trie?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Names are distinct, non-empty strings. For each name, return the shortest prefix that no other name in the list shares. If a name is a prefix of another (like Get-Item and Get-ItemProperty), no pr...
High-Level Design
Insert every name into a trie and increment a counter on each node the name passes through. A node's count is the number of names sharing that prefix. For each name, walk its path and stop at the firs...