We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3a8e0cf commit aac5cfdCopy full SHA for aac5cfd
PiCode.py
@@ -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