#K63692. Check if a String is Balanced
Check if a String is Balanced
Check if a String is Balanced
Given a string and its length n, determine whether the string is balanced. A string is considered balanced if and only if
\[
\text{sorted}(s[0:\frac{n}{2}]) = \text{sorted}(s[\frac{n}{2}:n])
\]
when the string is divided into two halves after converting all characters to lowercase. If n is odd, the string is automatically unbalanced.
Input Constraints:
- The first line contains an integer n, the length of the string.
- The second line contains the string s of length n.
Output: Print YES
if the string is balanced; otherwise, print NO
.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- An integer n representing the length of the string.
- A string s of length n.
outputFormat
Output a single line to standard output (stdout):
Print YES
if the string is balanced according to the definition above or NO
otherwise.
6
aaBBaa
YES