forked from Srinivas11789/AlgorithmNuggets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeau.py
More file actions
68 lines (60 loc) · 1.66 KB
/
beau.py
File metadata and controls
68 lines (60 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/python
import sys
def beautifulPairs(A, B):
# Calculate number of beautiful pairs
# Sort both the arrays
#A = sorted(A)
#B = sorted(B)
#print A
#print B
# Simple logic that passes, logic by ccordero from hr discuss but ON2
res = 0
#Iterate the full array A
for i in range(len(A)):
# Iterate B such that its length is updated every time
for j in range(len(B)):
# If beautiful pair remove from B
if A[i] == B[j]:
#print j
B.pop(j)
# Update the result everytime and break to reload B after pop
res += 1
break
#print A
#print B
#print A
#print B
# If result is equal to N all the elements have been exhausted
if res == len(A):
return res - 1
else:
return res + 1
"""
pairs = 0
change = {}
count = 0
for i in range(len(A)):
if A[i] == B[i]:
pairs += 1
if A[i] not in change:
change[A[i]] = 0
else:
#if A[i] not in change:
# change[A[i]] = 0
#change[A[i]] += 1
if B[i] not in change:
change[B[i]] = 0
change[B[i]] += 1
maxi = 0
for key, value in change.items():
if value > maxi:
maxi = value
return pairs + maxi
#return pairs + count
"""
if __name__ == "__main__":
n = int(raw_input().strip())
A = map(int, raw_input().strip().split(' '))
B = map(int, raw_input().strip().split(' '))
result = beautifulPairs(A, B)
print result