-
Notifications
You must be signed in to change notification settings - Fork 22
/
check if two arrays are equal or not
62 lines (54 loc) · 1.42 KB
/
check if two arrays are equal or not
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
60
61
62
/*
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.
Input:
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains 3 lines of
input. The first line contains an integer N denoting the size of the array. The second line contains element of array A[]. The third line
contains elements of the array B[].
Output:
For each test case, print 1 if the arrays are equal else print 0.
Constraints:
1<=T<=100
1<=N<=107
1<=A[],B[]<=1018
Example:
Input:
2
5
1 2 5 4 0
2 4 5 0 1
3
1 2 5
2 4 15
Output:
1
0
Explanation:
Testcase1:
Input : A[] = {1, 2, 5, 4, 0}; B[] = {2, 4, 5, 0, 1};
Output : 1
Testcase2:
Input : A[] = {1, 2, 5}; B[] = {2, 4, 15};
Output : 0
*/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
int t; cin>>t; while(t--){
ll n; cin>>n;
ll a[n],b[n],s=0,s1=0,x=0,x1=0;
for(int i=0; i<n; i++){
cin>>a[i];
s+=a[i];
x^=a[i];
}
for(int i=0; i<n; i++){
cin>>b[i];
s1+=b[i];
x1^=b[i];
}
s==s1 && x==x1? cout<<1<<endl : cout<<0<<endl;
}
return 0;
}