-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathplaying_with_string.py
executable file
·58 lines (49 loc) · 1.73 KB
/
playing_with_string.py
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
'''
problem--
Chef usually likes to play cricket, but now, he is bored of playing it too much, so he is trying new games with strings. Chef's friend Dustin gave him binary strings S and R, each with length N, and told him to make them identical. However, unlike Dustin, Chef does not have any superpower and Dustin lets Chef perform only operations of one type: choose any pair of integers (i,j) such that 1≤i,j≤N and swap the i-th and j-th character of S. He may perform any number of operations (including zero).
For Chef, this is much harder than cricket and he is asking for your help. Tell him whether it is possible to change the string S to the target string R only using operations of the given type.
Input--
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N.
The second line contains a binary string S.
The third line contains a binary string R.
Output--
For each test case, print a single line containing the string "YES" if it is possible to change S to R or "NO" if it is impossible (without quotes).
Constraints--
1≤T≤400
1≤N≤100
|S|=|R|=N
S and R will consist of only '1' and '0'
Example Input
2
5
11000
01001
3
110
001
Example Output
YES
NO
Explanation--
Example case 1: Chef can perform one operation with (i,j)=(1,5). Then, S will be "01001", which is equal to R.
Example case 2: There is no sequence of operations which would make S equal to R.
'''
#code is here
t=int(input())
for x in range(t):
n=int(input())
s=input()
r=input()
s1=0
r1=0
for i in s:
if i=='1':
s1=s1+1
for i in r:
if i=='1':
r1=r1+1
if r1==s1:
print("YES")
else:
print("NO")