Skip to content
DeepForgeby svx
All problems
MediumInformation Theoryinfo-292

Prefix-Free Check

Problem

Return True when no codeword in the list is a prefix of another codeword. Duplicate codewords count as a violation because each is a prefix of the other. Empty and single-element lists are prefix-free.

Hint

Only compare each unordered pair once; startswith covers both directions.

Test cases

case 1
in: [["0","10","11"]]
expected: true
case 2
in: [["0","01"]]
expected: false
case 3
in: [["00","01","10","11"]]
expected: true
case 4
in: [["1","1"]]
expected: false
case 5
in: [[]]
expected: true
Starter codePython
def is_prefix_free(words):
    # Your code here
    pass

5 test cases · run your code against them in the editor