There is a binary string
For example, suppose
- In the first operation, we can select the prefix of length
8 since it has four0 's and four1 's:[01110100]00→[10001011]00 . - In the second operation, we can select the prefix of length
2 since it has one0 and one1 :[10]00101100→[01]00101100 . - It is illegal to select the prefix of length
4 for the third operation, because it has three0 's and one1 .
Can you transform the string
The first line contains a single integer
The first line of each test case contains a single integer
The following two lines contain strings
The sum of
For each test case, output "YES" if it is possible to transform
5 10 0111010000 0100101100 4 0000 0000 3 001 000 12 010101010101 100110011010 6 000111 110100
YES YES NO YES NO
The first test case is shown in the statement.
In the second test case, we transform
In the third test case, there is no legal operation, so it is impossible to transform
In the fourth test case, here is one such transformation:
- Select the length
2 prefix to get100101010101 . - Select the length
12 prefix to get011010101010 . - Select the length
8 prefix to get100101011010 . - Select the length
4 prefix to get011001011010 . - Select the length
6 prefix to get100110011010 .
In the fifth test case, the only legal operation is to transform
0 Comments
If you have any doubts/suggestion/any query or want to improve this article, you can comment down below and let me know. Will reply to you soon.