Ctrl K

No Number Starts Another

Easy
A phone book phones holds numbers as strings of digits. The exchange connects a call as soon as the dialled digits match a whole number, so a number that begins with another number can never be reached. Return True if no number in the list is a prefix of another number in the list, and False otherwise. A number listed twice also counts as a conflict.
Example 1
phones=["112", "911", "9112"] → False

"9112" starts with "911", so the answer is False.

Example 2
phones=["5550", "5551", "0555"] → True

No number is the beginning of another one.

Example 3
phones=["42", "42"] → False

Duplicates count too: each one is the beginning of the other.

Constraints
  • 2 ≤ len(phones) ≤ 50
  • 1 ≤ len(phones[i]) ≤ 50
  • phones[i] contains only the digits 0–9
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsDictionary Words in a Text EasyDistinct Word Shorthands HardMost Searched Words MediumWord Grown Letter by Letter MediumWords Hidden in a Text Medium
loading Python…
Input
phones=["112", "911", "9112"]
Expected
False

Run checks the first 3 tests in your browser. Submit checks all 98 tests on the server, hidden ones included.