Tap here to switch tabs
Problem
Submissions

Problem: Special Binary String

med
30 min
Try to solve the Special Binary String problem.

Statement

A special binary string is a binary string satisfying both of the following properties:

  • The count of '0's equals the count of '1's.

  • Every prefix of the string contains at least as many '1's as '0's.

You are given a special binary string s. A single move consists of selecting two consecutive, non-empty special substrings of s and swapping them. Two substrings are considered consecutive if the last character of the first substring is at exactly one index before the first character of the second substring.

Return the lexicographically largest string achievable after performing any number of such moves on s.

Constraints:

  • 11 \leq s.length 50\leq 50

  • s[i] is either '0' or '1'

  • s is guaranteed to be a special binary string

Unlock AI-Powered LearningUpgrade to smarter learning with instant explanations of Ask Agent, Personalized Interview Prep, Real-World Projects, 3 AI Mock Interviews per month, and Personalized Paths
Tap here to switch tabs
Problem
Submissions

Problem: Special Binary String

med
30 min
Try to solve the Special Binary String problem.

Statement

A special binary string is a binary string satisfying both of the following properties:

  • The count of '0's equals the count of '1's.

  • Every prefix of the string contains at least as many '1's as '0's.

You are given a special binary string s. A single move consists of selecting two consecutive, non-empty special substrings of s and swapping them. Two substrings are considered consecutive if the last character of the first substring is at exactly one index before the first character of the second substring.

Return the lexicographically largest string achievable after performing any number of such moves on s.

Constraints:

  • 11 \leq s.length 50\leq 50

  • s[i] is either '0' or '1'

  • s is guaranteed to be a special binary string

Unlock AI-Powered LearningUpgrade to smarter learning with instant explanations of Ask Agent, Personalized Interview Prep, Real-World Projects, 3 AI Mock Interviews per month, and Personalized Paths