The problem over here introduces an new type of strings: if you split the string into equal halfs and swap the pairs, it produces the same output as sorting the string. We call that a half-sort.
Given a purely ASCII string, check if the string is in a half-sort.
An example of a half-sort string
node is a half-sort string, because if you sort by codepoints (note that the codepoints are in decimal, not binary):
n 110 o 111 d 100 e 101
That gets turned into:
d 100 e 101 n 110 o 111
You'll see that the
deno conversion is exactly moving the right half to the left position.
- For odd-length strings, splitting should make the first half longer.
- Sorting a string means sorting the string based on the codepoints of the characters.
Reference program & test cases
Here is the reference program I made for checking my test cases.
node -> True rum -> True aaa -> True deno -> False rim -> False