#K15526. Rearrange to Match
Rearrange to Match
Rearrange to Match
Given two binary strings s
and t
each of length n, determine if it is possible to rearrange t
such that it becomes exactly equal to s
. Rearranging means permuting the characters of t
in any order. The necessary and sufficient condition for such a rearrangement is that both strings have the same count of '0'
and '1'
. Output Yes
if the rearrangement is possible; otherwise, output No
.
inputFormat
The input is given on three separate lines:
- The first line contains a single integer n, the length of the binary strings.
- The second line contains the binary string
s
. - The third line contains the binary string
t
.
outputFormat
Output a single line containing Yes
if t
can be rearranged to match s
, and No
otherwise.
4
1100
0011
Yes
</p>