Skip to content

Commit aac5cfd

Browse files
authored
Create PiCode.py
1 parent 3a8e0cf commit aac5cfd

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

PiCode.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# you can write to stdout for debugging purposes, e.g.
2+
# print("this is a debug message")
3+
4+
def solution(p, q):
5+
distinct_strings = [{}]
6+
seen = {}
7+
8+
for left, right in zip(p, q):
9+
if seen.get((left, right)):
10+
continue
11+
seen[(left, right)] = True
12+
for key in distinct_strings:
13+
left_match, right_match = key.get(left), key.get(right)
14+
if not (left_match or right_match):
15+
if right != left:
16+
distinct_strings.append(key.copy())
17+
distinct_strings[-1][right] = True
18+
key[left] = True
19+
distinct_strings = list(set([frozenset(d.items()) for d in distinct_strings]))
20+
distinct_strings = [dict(s) for s in distinct_strings]
21+
return min([len(d) for d in distinct_strings])

0 commit comments

Comments
 (0)