Check if two arrays are equal or not

TopicDifficultyCompanies
Hash Table
EASY
Amazon
Goldman Sachs

Given two integer arrays(arr1 and arr2) of equal length, Check if the given arrays are equal or not.

Problem Note

  • Two arrays are said to be equal if they contain the same set of elements, but the permutations of the elements may differ.
  • If there is a repetition of any element in the arrays, then the count of that element must be the same in both the arrays to be equal.
  • If the arrays are equal, the output will be 1, else the output will be 0.

Example 1

Input: arr1[] = [3, 8, 9, 1] , arr2[] = [9, 3, 1, 8]  
Output: 1
Explanation: There is no repetion of any element in the arrays, and both contains same set of elements. Hence, the output is 1.

Example 2

Input: arr1[] = [1, 2, 5, 2, 1] , arr2[] = [2, 1, 2, 1, 5] 
Output: 1
Explanation: There is a repetion of element 1 and 2 in the arrays but the count is same in both. Also, both contains same set of elements. Hence, the output is 1.

Example 3

Input: arr1[] = [1, 2, 2, 7, 1] , arr2[] = [2, 1, 2, 7] 
Output: 0
Explanation: There is a repetion of element 1 and 2 in the arrays but the count of element 1 not the same in both. Hence, the output is 0.

Example 4

Input: arr1[] = [0, 5, 0] , arr2[] = [5, 0, 5] 
Output: 0
Explanation: There is a repetion of element 0 and 5 in the arrays but the count of these elements is not the same in both. Hence, the output is 0.

Code Editor

Practice and Learn

Best way to learn is through solving real problems. Practice this problem in this code editor.