Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f2cf104

Browse files
Check for equality of two arrays
1 parent c897d87 commit f2cf104

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'''
2+
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.
3+
Note : If there are repetitions, then counts of repeated elements must also be same for two array to be equal.
4+
5+
Input:
6+
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[].
7+
8+
Output:
9+
For each test case, print 1 if the arrays are equal else print 0.
10+
11+
Constraints:
12+
1<=T<=100
13+
1<=N<=107
14+
1<=A[],B[]<=1018
15+
16+
Example:
17+
Input:
18+
2
19+
5
20+
1 2 5 4 0
21+
2 4 5 0 1
22+
3
23+
1 2 5
24+
2 4 15
25+
26+
Output:
27+
1
28+
0
29+
30+
Explanation:
31+
Testcase1:
32+
Input : A[] = {1, 2, 5, 4, 0}; B[] = {2, 4, 5, 0, 1};
33+
Output : 1
34+
35+
Testcase2:
36+
Input : A[] = {1, 2, 5}; B[] = {2, 4, 15};
37+
Output : 0
38+
'''
39+
def equal(arr1, arr2):
40+
res = 0
41+
for i in range(len(arr1)):
42+
res ^= arr1[i]
43+
res ^= arr2[i]
44+
return 0 if res else 1
45+
46+
t = int(input())
47+
while t > 0:
48+
n = int(input())
49+
arr1 = list(map(int, input().split()))
50+
arr2 = list(map(int, input().split()))
51+
print(equal(arr1, arr2))
52+
t -= 1

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /