Skip to content

Practice Special Binary String

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#761
LeetCode Problem

Special Binary String

Problem Statement

A binary string is special when it has equal numbers of 0 and 1, and every prefix has at least as many 1 characters as 0 characters. Given a special string s, one move swaps two adjacent nonempty substrings that are themselves special. Return the lexicographically greatest string obtainable after any number of such moves.

Source: Special Binary String on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "11011000"
Output
"11100100"

# Example 2

Input
s = "10"
Output
"10"

Constraints

1 <= s.length <= 50
s[i] is either '0' or '1'.
s is a special binary string.

Related LeetCode Problems

Practice more problems similar to Special Binary String.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.