aboutsummaryrefslogtreecommitdiff
path: root/challenge-115/lubos-kolouch/python/ch-1.py
blob: 32cb19a7c86be96a91fa9df7cbccef900f6d825f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from collections import defaultdict


def string_chain(arr):
    in_degree = defaultdict(int)
    out_degree = defaultdict(int)

    for s in arr:
        in_degree[s[0]] += 1
        out_degree[s[-1]] += 1

    return in_degree == out_degree


# Test
print(string_chain(["abc", "dea", "cd"]))  # Output: 1