Dsa
Trie
Medium
Phone Number Abbreviation
Given a list of phone numbers and a query phone number, find all abbreviations of the query phone number that can be formed by removing at least one digit from it. An abbreviation is valid if it matches any number in the phone number list. Output each valid abbreviation in lexicographic order.
Input Format:
- The first line contains an integer n (1 ≤ n ≤ 100) - the number of phone numbers.
- The next n lines each contain a phone number of variable length (up to 15 digits).
- The last line contains a query phone number.
Output Format:
- Output all valid abbreviations of the query phone number in lexicographic order, one abbreviation per line.
Example:
Input:
3
1234567890
2345678901
3456789012
123456
Output:
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
Key concepts
triestringabbreviation
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