-
Notifications
You must be signed in to change notification settings - Fork 0
/
Check if two arrays are equal or not.cpp
59 lines (50 loc) · 1.27 KB
/
Check if two arrays are equal or not.cpp
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
//{ Driver Code Starts
//Initial function template for C++
#include<bits/stdc++.h>
using namespace std;
#define ll long long
// } Driver Code Ends
//User function template for C++
class Solution{
public:
//Function to check if two arrays are equal or not.
bool check(vector<ll> A, vector<ll> B, int N) {
map<int,int>mapping;
map<int,int>mapping2;
for(int i=0;i<N;i++){
mapping[A[i]]++;
}
for(int i=0;i<N;i++){
mapping2[B[i]]++;
}
for(int i=0;i<N;i++){
int no=A[i];
if(mapping[no]!=mapping2[no]) return false;
}
return true;
}
};
//{ Driver Code Starts.
int main()
{
int t;
cin>>t;
while(t--) {
int n;
cin>>n;
vector<ll> arr(n,0),brr(n,0);
// increase the count of elements in first array
for(ll i=0;i<n;i++)
cin >> arr[i];
// iterate through another array
// and decrement the count of elements
// in the map in which frequency of elements
// is stored for first array
for(ll i=0;i<n;i++)
cin >> brr[i];
Solution ob;
cout << ob.check(arr,brr,n) << "\n";
}
return 0;
}
// } Driver Code Ends