"""
shortest unique path using trie
"""

from collections import defaultdict


class Solution:
    def prefix(self, words):
        prefixes = defaultdict(int)
        for word in words:
            for i in range(1, len(word)):
                prefixes[word[:i]] += 1
        output = []
        for word in words:
            result = word
            for i in range(1, len(word)):
                pref = word[:i]
                if prefixes[pref] == 1:
                    result = pref
                    break
            output.append(result)
        return output


words_list = ["dog", "dove", "duck", "zebra"]
print(Solution().prefix(words_list))

769d99ee766805da7bbdc22da7a94df2985dd624
<mask token>


class Solution:

    def prefix(self, words):
        prefixes = defaultdict(int)
        for word in words:
            for i in range(1, len(word)):
                prefixes[word[:i]] += 1
        output = []
        for word in words:
            result = word
            for i in range(1, len(word)):
                pref = word[:i]
                if prefixes[pref] == 1:
                    result = pref
                    break
            output.append(result)
        return output


<mask token>

<mask token>


class Solution:

    def prefix(self, words):
        prefixes = defaultdict(int)
        for word in words:
            for i in range(1, len(word)):
                prefixes[word[:i]] += 1
        output = []
        for word in words:
            result = word
            for i in range(1, len(word)):
                pref = word[:i]
                if prefixes[pref] == 1:
                    result = pref
                    break
            output.append(result)
        return output


<mask token>
print(Solution().prefix(words_list))

<mask token>


class Solution:

    def prefix(self, words):
        prefixes = defaultdict(int)
        for word in words:
            for i in range(1, len(word)):
                prefixes[word[:i]] += 1
        output = []
        for word in words:
            result = word
            for i in range(1, len(word)):
                pref = word[:i]
                if prefixes[pref] == 1:
                    result = pref
                    break
            output.append(result)
        return output


words_list = ['dog', 'dove', 'duck', 'zebra']
print(Solution().prefix(words_list))

<mask token>
from collections import defaultdict


class Solution:

    def prefix(self, words):
        prefixes = defaultdict(int)
        for word in words:
            for i in range(1, len(word)):
                prefixes[word[:i]] += 1
        output = []
        for word in words:
            result = word
            for i in range(1, len(word)):
                pref = word[:i]
                if prefixes[pref] == 1:
                    result = pref
                    break
            output.append(result)
        return output


words_list = ['dog', 'dove', 'duck', 'zebra']
print(Solution().prefix(words_list))

"""
shortest unique path using trie
"""

from collections import defaultdict


class Solution:
    def prefix(self, words):
        prefixes = defaultdict(int)
        for word in words:
            for i in range(1, len(word)):
                prefixes[word[:i]] += 1
        output = []
        for word in words:
            result = word
            for i in range(1, len(word)):
                pref = word[:i]
                if prefixes[pref] == 1:
                    result = pref
                    break
            output.append(result)
        return output


words_list = ["dog", "dove", "duck", "zebra"]
print(Solution().prefix(words_list))
