Question bank › Trie
Dsa Trie Warm-up

Phone Directory Search

You are building a phone directory application where users can enter names and their corresponding phone numbers. Implement a trie that allows for efficient insertion and search based on prefixes of names. The input consists of a sequence of commands: 1. 'ADD <name> <phone>' - Add a person's name and phone number to the directory. 2. 'SEARCH <prefix>' - Output all names whose names begin with the given prefix. Each result should be printed on a new line and sorted alphabetically. Example: INPUT: ADD Alice 1234 ADD Alex 5678 SEARCH Al SEARCH A OUTPUT: Alex Alice

Key concepts

triedirectorysearch

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.