aboutsummaryrefslogtreecommitdiff
path: root/challenge-057/lubos-kolouch/python/ch-2.py
blob: d8dd13931122111af876b4c71e7900c150372a18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from typing import List


def shortest_unique_prefixes(words: List[str]) -> List[str]:
    result = []

    for word in words:
        prefix = ""
        for char in word:
            prefix += char
            if not any(res.startswith(prefix) for res in result):
                result.append(prefix)
                break

    return result

if __name__ == "__main__":
    input_list = ["alphabet", "book", "carpet", "cadmium", "cadeau", "alpine"]
    result = shortest_unique_prefixes(input_list)

    print(result)