Check That a Set of Dial Codes Is Prefix-Free

Last updated: November 29, 2026

Quick Overview

Given a list of phone dial codes, return False if any code is a prefix of another (which would make dialing ambiguous), otherwise True.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


Given a list of phone dial codes, return False if any code is a prefix of another (which would make dialing ambiguous), otherwise True.

An easy Google online assessment problem framed around validating a telephony routing table for Google Voice. It checks detecting prefix conflicts in a single insertion pass over a trie, in both directions.

What the Interviewer Expects
  • Insert codes into a trie with end markers
  • Detect when a new code passes through an existing end
  • Detect when a new code ends at a node that already has children
  • Treat duplicates as conflicts
  • Compare with the sort-and-check-neighbors approach
Key Topics to Cover
trie
prefix-free codes
validation
sorting
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you report every conflicting pair?
  • How would you fix conflicts by choosing the fewest codes to remove?
  • How does this relate to Huffman codes?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: codes, strings of digits. Output: True if no code is a prefix of a different code and there are no duplicates, else False....

High-Level Design

Insert codes one at a time. A conflict appears in exactly two ways. Either the new code, while walking, passes a node that already marks the end of an earlier code (an earlier code is a prefix of the ...


Submit Your Answer
Markdown supported