Dsa
Trie
Easy
Unique Namespace Identifiers
You are designing a system to generate the shortest unique identifier for a list of usernames. For each username, find the shortest prefix that is NOT a prefix of any other username in the set. If a username is entirely a prefix of another (e.g., 'art' and 'artist'), the shorter one cannot be shortened further, so output the whole string.
Example:
Input:
3
apple
apply
dog
Output:
appl-e
appl-y
d
(Note: In this specific problem format, for 'apple' and 'apply', 'appl' is shared, so 'apple' becomes 'apple' and 'apply' becomes 'apply' because the first unique char is the 5th one).
Key concepts
triestringsshortest-unique-prefix
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now