Given two arrays A and B of equal size N, the task is to find if given arrays are equal or not. Two arrays are said to be equal if both of them contain same set of elements, arrangements (or permutation) of elements may be different though.
Note : If there are repetitions, then counts of repeated elements must also be same for two array to be equal.
Example 1:
Input:
N = 5
A[] = {1,2,5,4,0}
B[] = {2,4,5,0,1}
Output: 1
Explanation: Both the array can be 
rearranged to {0,1,2,4,5}
Example 2:
Input:
N = 3
A[] = {1,2,5}
B[] = {2,4,15}
Output: 0
Explanation: A[] and B[] have only 
one common value.
Your Task:
Complete check() function which takes both the given array and their size as function arguments and returns true if the arrays are equal else returns false.The 0 and 1 printing is done by the driver code.
Expected Time Complexity : O(N)
Expected Auxilliary Space : O(N)
Constraints:
1<=N<=10^{7}
1<=A[],B[]<=10^{18}

Difficulty: EASY
Tags: String algorithms

Sorting

Data structures
Skill types: Sorting

Data structures
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)

Starter code:
#User function Template for python3

class Solution:
    #Function to check if two arrays are equal or not.
    def check(self,A,B,N):
        
        #return: True or False
        
        #code here

Solutions:
class Solution:

	def check(self, A, B, N):
		if sorted(A) == sorted(B):
			return True
		else:
			return False


class Solution:

	def check(self, A, B, N):
		A.sort()
		B.sort()
		if A == B:
			return True
		return False


class Solution:

	def check(self, A, B, N):
		A.sort()
		B.sort()
		if A == B:
			return 1
		else:
			return 0


class Solution:

	def check(self, A, B, N):
		if len(A) != len(B):
			return 0
		A.sort()
		B.sort()
		for i in range(N):
			if A[i] != B[i]:
				return 0
		return 1


from collections import Counter

class Solution:

	def check(self, A, B, N):
		a = Counter(A)
		b = Counter(B)
		for c in a:
			if a[c] != b[c]:
				return False
		for c in b:
			if b[c] != a[c]:
				return False
		return True


class Solution:

	def check(self, A, B, N):
		a = sorted(A)
		b = sorted(B)
		if a == b:
			return True
		return False


class Solution:

	def check(self, A, B, N):
		d = dict()
		for i in A:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		result = True
		for i in B:
			if i in d:
				d[i] -= 1
				if d[i] < 0:
					result = False
					break
			else:
				result = False
				break
		return result


class Solution:

	def check(self, A, B, N):
		B.sort()
		A.sort()
		for (i, j) in zip(A, B):
			if i != j:
				return 0
				break
		return 1


class Solution:

	def check(self, A, B, N):
		dict1 = {}
		for i in A:
			if i not in dict1:
				dict1[i] = 1
			else:
				dict1[i] += 1
		dict2 = {}
		for i in B:
			if i not in dict2:
				dict2[i] = 1
			else:
				dict2[i] += 1
		if dict1 == dict2:
			return True
		return False


class Solution:

	def check(self, A, B, N):
		mp = {}
		for i in range(N):
			if A[i] in mp.keys():
				mp[A[i]] += 1
			else:
				mp[A[i]] = 1
		for i in range(N):
			if B[i] not in mp.keys():
				return False
			else:
				mp[B[i]] -= 1
		for i in mp.keys():
			if mp[i] != 0:
				return False
		return True


class Solution:

	def check(self, A, B, N):
		cnt = 0
		A.sort()
		B.sort()
		for i in range(N):
			if A[i] == B[i]:
				cnt += 1
		if cnt == N:
			return True
		else:
			return False


class Solution:

	def check(self, A, B, N):
		A.sort()
		B.sort()
		for i in range(len(A)):
			if A[i] != B[i]:
				return False
		return True


class Solution:

	def check(self, a, b, n):
		return sorted(a) == sorted(b)


class Solution:

	def check(self, A, B, N):
		if len(A) != len(B):
			return False
		A = sorted(A)
		B = sorted(B)
		i = 0
		while i < len(A):
			if A[i] != B[i]:
				return False
			i += 1
		return True


class Solution:

	def check(self, A, B, N):
		if len(A) != len(B):
			return False
		else:
			sortA = sorted(A)
			sortB = sorted(B)
			if sortA == sortB:
				return True
		return False


from heapq import *

class Solution:

	def check(self, A, B, N):
		heap1 = []
		heap2 = []
		c = 0
		for i in A:
			heappush(heap1, i)
		for i in B:
			heappush(heap2, i)
		while c < len(A):
			if heappop(heap1) != heappop(heap2):
				return 0
			else:
				c += 1
				if c == len(A):
					return 1


class Solution:

	def check(self, A, B, N):
		freqA = {}
		freqB = {}
		for num in A:
			if num in freqA:
				freqA[num] += 1
			else:
				freqA[num] = 1
		for num in B:
			if num in freqB:
				freqB[num] += 1
			else:
				freqB[num] = 1
		return int(freqA == freqB)


class Solution:

	def check(self, A, B, N):
		A.sort()
		B.sort()
		count = 0
		return A == B


class Solution:

	def check(self, arr1, arr2, N):
		testDic = {}
		for i in range(N):
			count = testDic.get(arr1[i], 0)
			testDic[arr1[i]] = count + 1
		for i in range(N):
			count = testDic.get(arr2[i], 0)
			if count == 0:
				return False
			else:
				testDic[arr2[i]] = count - 1
		return True


class Solution:

	def check(self, A, B, N):
		count = {}
		for num in A:
			if num in count:
				count[num] += 1
			else:
				count[num] = 1
		for num in B:
			if num not in count:
				return False
			count[num] -= 1
		for num in count:
			if count[num] != 0:
				return False
		return True


class Solution:

	def check(self, A, B, N):
		Sort1 = sorted(A)
		Sort2 = sorted(B)
		for i in range(N):
			if Sort1[i] != Sort2[i]:
				return False
		return True


class Solution:

	def check(self, A, B, N):
		if len(A) != len(B):
			return False
		dict = {}
		for i in A:
			if i in dict.keys():
				dict[i] += 1
			else:
				dict[i] = 1
		for i in B:
			if i not in dict.keys():
				return False
			else:
				dict[i] -= 1
		for i in dict.keys():
			if dict[i] != 0:
				return False
		return True


import heapq

class Solution:

	def check(self, A, B, N):
		a1 = []
		b1 = []
		for x in range(0, len(A)):
			heapq.heappush(a1, A[x])
			heapq.heappush(b1, B[x])
		a1 = [heapq.heappop(a1) for x in range(N)]
		b1 = [heapq.heappop(b1) for x in range(N)]
		return a1 == b1


class Solution:

	def check(self, A, B, N):
		dict = {}
		for i in range(N):
			k = A[i]
			if k in dict.keys():
				dict[k] += 1
			else:
				dict[k] = 1
		for i in range(N):
			k = B[i]
			if k in dict.keys():
				if dict[k] > 0:
					dict[k] -= 1
				else:
					return False
			else:
				return False
		return True


class Solution:

	def check(self, A, B, N):
		return sorted(A) == sorted(B)


class Solution:

	def check(self, A, B, N):
		if N != len(B):
			return False
		count = {}
		for num in A:
			count[num] = count.get(num, 0) + 1
		for num in B:
			if num not in count or count[num] == 0:
				return False
			count[num] -= 1
		for num in count:
			if count[num] != 0:
				return False
		return True


class Solution:

	def check(self, A, B, N):
		(a, b) = ({}, {})
		for i in range(N):
			a[A[i]] = a.get(A[i], 0) + 1
			b[B[i]] = b.get(B[i], 0) + 1
		a = set(((i, a[i]) for i in a))
		b = set(((i, b[i]) for i in b))
		return a == b


class Solution:

	def check(self, A, B, N):
		i = 0
		A.sort()
		B.sort()
		while i < N:
			if A[i] == B[i]:
				temp = 0
			else:
				return False
			i += 1
		if temp == 0:
			return True
		else:
			return False


class Solution:

	def check(self, A, B, N):
		A.sort()
		B.sort()
		return A == B


class Solution:

	def check(self, A, B, N):
		freqA = {}
		freqB = {}
		for i in range(N):
			freqA[A[i]] = freqA.get(A[i], 0) + 1
			freqB[B[i]] = freqB.get(B[i], 0) + 1
		return freqA == freqB


class Solution:

	def check(self, A, B, N):
		dic = {}
		for i in range(N):
			if A[i] in dic.keys():
				dic[A[i]] += 1
			else:
				dic[A[i]] = 1
		for i in range(N):
			if B[i] in dic.keys():
				dic[B[i]] -= 1
			else:
				return 0
		for i in dic.keys():
			if dic[i] != 0:
				return 0
		return 1


class Solution:

	def check(self, A, B, N):
		if N != len(B):
			return False
		count = {}
		for i in range(N):
			if A[i] not in count:
				count[A[i]] = 1
			else:
				count[A[i]] += 1
		for i in range(N):
			if B[i] not in count:
				return False
			else:
				count[B[i]] -= 1
				if count[B[i]] < 0:
					return False
		return True


class Solution:

	def check(self, A, B, N):
		if len(A) == N and len(B) == N:
			A.sort()
			B.sort()
			if A == B:
				return True
		else:
			return False


class Solution:

	def check(self, A, B, N):
		A.sort()
		B.sort()
		if A == B:
			return 1
		return 0
		if sum(A) == sum(B) and len(A) == len(B):
			for value in A:
				if value in B:
					B.remove(value)
			if len(B) > 0:
				return 0
			return 1
		return 0


class Solution:

	def check(self, A, B, N):
		A_dict = {}
		B_dict = {}
		for (x, y) in zip(A, B):
			A_dict[x] = A_dict.get(x, 0) + 1
			B_dict[y] = B_dict.get(y, 0) + 1
		if len(A_dict) != len(B_dict):
			return False
		for x in A_dict.keys():
			if A_dict[x] != B_dict.get(x, 0):
				return False
		return True


from collections import Counter

class Solution:

	def check(self, A, B, N):
		cnt_A = Counter(A)
		cnt_B = Counter(B)
		for (inx, val) in cnt_A.items():
			if inx not in cnt_B or val != cnt_B[inx]:
				return False
		return True