Special Binary String
Real-world version: Largest Rearrangement of a Nested TapeThe statement here is our own: the same inputs, outputs and technique.
A tape of '0' and '1' is nested when it holds as many of each and, reading from the left, the count of '1' never falls behind the count of '0'.
The tape s is nested. You may repeatedly pick two nested stretches that sit directly next to each other and swap them, as often as you like.
Return the largest tape obtainable, comparing tapes as text.
Examples
Example 1
- Input
- s = "110100111000"
- Output
- "111000110100"
The tape breaks into the two pieces 110100 and 111000. Neither has anything worth reordering inside it, and as text 111000 is the larger, so it goes first.
Example 2
- Input
- s = "1010"
- Output
- "1010"
Two identical pieces sit side by side, so no swap changes anything.
Example 3
- Input
- s = "101100"
- Output
- "110010"
The pieces are 10 and 1100, and putting the larger first gives 110010.
Constraints
- 1 <= s.length <= 50
- s[i] is either '0' or '1'
- s is nested
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def make_largest_special(s: str) -> str:public String makeLargestSpecial(String s)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 13 test cases: 13 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's