def comp(array_a, array_b):
if (not array_a or not array_b):
return False
occurrences_a = {}
occurrences_b = {}
# Counts the occurrence for array a
for num in array_a:
if not (num in occurrences_a):
occurrences_a[num] = 1
else:
occurrences_a[num] += 1
# Counts the occurrences for array b
for num in array_b:
if not (num in occurrences_b):
occurrences_b[num] = 1
else:
occurrences_b[num] += 1
for item in array_a:
# Checks whether the squared value of array a is in b and if their occurrences are the same
if not ((item ** 2 in occurrences_b) and (occurrences_a[item] == occurrences_b[item ** 2])):
return False
else:
return True