Question bank › Trie
Dsa Trie Easy

Unique Phone Number Finder

You are developing a system to manage and validate unique phone numbers. Implement a Trie structure for phone numbers that allows you to insert numbers and check how many unique numbers start with a given prefix. Implement the following methods: 1. `insert_number(number: str)` - inserts a phone number into the trie. 2. `count_unique_prefix(prefix: str) -> int` - returns the count of unique phone numbers that start with the given prefix. Input format: - The first line contains an integer, N (1 ≤ N ≤ 500), the number of operations. - The following N lines contain operations in the format: - `insert <number>` (where <number> contains digits), - `count <prefix>` (where <prefix> contains digits). Output format: - For each `count` operation, print the count of unique numbers started with that prefix. Example: Input: 4 insert 123 insert 124 insert 123456 count 123 count 12 Output: 2 2

Key concepts

triedata structuresunique

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.