Two arrays of size N are called identical arrays if they contain the same elements. The order of elements in both arrays could be different; however, both the arrays must contain same elements. You are given two arrays of size N.
You need to determine if the arrays are identical or not.
Example 1:
 
Input : A[] = {1, 2, 3, 4, 5}, B[] = {3, 4, 1, 2, 5}
Output : 1
Explanation:
Here we can see array A[] = [1, 2, 3, 4, 5] and 
B[] = [3, 4, 1, 2, 5]. If we look both the array then we 
can get that array B is the permutation of A. So, both array
are identical. 
Example 2:
Input : A[] = {1, 2, 4}, B[] = {3, 2, 1} 
Output : 0 
 
Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function check() that takes an array (arr), another array (brr), size of both array (n), and return the 1 if both the array are identical else 0. The driver code takes care of the printing.
Expected Time Complexity: O(NLog(N)).
Expected Auxiliary Space: O(1).
 
Constraints:
1 ≤ N ≤ 10^{5}
0 ≤ A[i] ≤ 9

Source: geeksforgeeks | Difficulty: EASY
Tags: Sorting

Data structures

Starter code: #User function Template for python3



def check (arr,  brr, n) : 

    #Complete the function





Solutions:
def check(arr, brr, n):
	arr.sort()
	brr.sort()
	if arr == brr:
		return 1
	else:
		return 0


from collections import Counter

def check(arr, brr, n):
	if Counter(arr) == Counter(brr):
		return 1
	else:
		return 0


def check(arr, brr, n):
	ans = sorted(arr) == sorted(brr)
	if ans:
		return 1
	else:
		return 0


def check(arr, brr, n):
	arr.sort()
	brr.sort()
	for i in range(n):
		if arr[i] != brr[i]:
			return 0
	return 1


def check(arr, brr, n):
	if sorted(arr) == sorted(brr):
		return 1
	return 0


def check(arr, brr, n):
	A = arr
	B = brr
	A.sort()
	B.sort()
	i = 0
	j = 0
	while i < len(A):
		if A[i] == B[j]:
			i += 1
			j += 1
		else:
			return 0
	return 1


def check(arr, brr, n):
	arr.sort()
	brr.sort()
	if len(arr) == len(brr) and arr == brr:
		return 1
	else:
		return 0


def bs(arr, low, high, key):
	while low <= high:
		mid = (low + high) // 2
		if arr[mid] == key:
			return True
		elif arr[mid] > key:
			high = mid - 1
		else:
			low = mid + 1
	return False

def check(arr, brr, n):
	brr.sort()
	arr.sort()
	for i in range(n):
		if arr[i] != brr[i]:
			return 0
	return 1


def check(arr, brr, n):
	a = sorted(arr)
	b = sorted(brr)
	c = 0
	for i in range(n):
		if a[i] == b[i]:
			c += 1
	if c == n:
		return 1
	else:
		return 0


def check(arr, brr, n):
	valid = 1
	arr.sort()
	brr.sort()
	for index in range(n):
		if arr[index] != brr[index]:
			valid = 0
			break
	return valid


def check(arr, brr, n):
	arr_sorted = sorted(arr)
	brr_sorted = sorted(brr)
	if arr_sorted == brr_sorted:
		return 1
	else:
		return 0


def check(arr, brr, n):
	for i in arr:
		if i not in brr:
			return 0
		else:
			brr.remove(i)
	else:
		return 1


def check(arr, brr, n):
	hashmap = {}
	ans = 1
	for i in range(n):
		if arr[i] in hashmap:
			hashmap[arr[i]] += 1
		else:
			hashmap[arr[i]] = 1
	for i in range(n):
		if brr[i] in hashmap:
			hashmap[brr[i]] -= 1
	for (key, value) in hashmap.items():
		if value != 0:
			ans = 0
			break
	return ans


def check(arr, brr, n):
	a = sorted(arr)
	b = sorted(brr)
	if a == b:
		return 1
	else:
		return 0


def check(arr, brr, n):
	dict1 = {}
	dict2 = {}
	for i in range(n):
		if arr[i] not in dict1:
			dict1[arr[i]] = 1
		else:
			dict1[arr[i]] += 1
		if brr[i] not in dict2:
			dict2[brr[i]] = 1
		else:
			dict2[brr[i]] += 1
	if dict1 == dict2:
		return 1
	return 0


def BinarySearch(a, l, h, k):
	if l <= h:
		mid = (l + h) // 2
		if a[mid] == k:
			return 1
		elif a[mid] < k:
			return BinarySearch(a, mid + 1, h, k)
		else:
			return BinarySearch(a, l, mid - 1, k)
	else:
		return 0

def check(arr, brr, n):
	arr = sorted(arr)
	brr = sorted(brr)
	for i in range(n):
		if arr[i] == brr[i]:
			continue
		else:
			return 0
	return 1


def check(arr, brr, n):
	memo1 = {}
	memo2 = {}
	for i in range(len(arr)):
		if arr[i] not in memo1:
			memo1[arr[i]] = 1
		else:
			memo1[arr[i]] = memo1[arr[i]] + 1
	for j in range(len(brr)):
		if brr[j] not in memo2:
			memo2[brr[j]] = 1
		else:
			memo2[brr[j]] = memo2[brr[j]] + 1
	for i in arr:
		if i in memo1 and i in memo2:
			if memo1[i] == memo2[i]:
				continue
			else:
				return 0
		else:
			return 0
	return 1


from bisect import bisect_left

def check(A, B, n):
	return 1 if sorted(A) == sorted(B) else 0


def check(arr, brr, n):
	arr.sort()
	brr.sort()
	return int(arr == brr)


def check(arr, brr, n):
	return int(sorted(arr) == sorted(brr))