<p><strong>Special binary strings</strong> are binary strings with the following two properties:</p>

<ul>
	<li>The number of <code>0</code>&#39;s is equal to the number of <code>1</code>&#39;s.</li>
	<li>Every prefix of the binary string has at least as many <code>1</code>&#39;s as <code>0</code>&#39;s.</li>
</ul>

<p>You are given a <strong>special binary</strong> string <code>s</code>.</p>

<p>A move consists of choosing two consecutive, non-empty, special substrings of <code>s</code>, and swapping them. Two strings are consecutive if the last character of the first string is exactly one index before the first character of the second string.</p>

<p>Return <em>the lexicographically largest resulting string possible after applying the mentioned operations on the string</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;11011000&quot;
<strong>Output:</strong> &quot;11100100&quot;
<strong>Explanation:</strong> The strings &quot;10&quot; [occuring at s[1]] and &quot;1100&quot; [at s[3]] are swapped.
This is the lexicographically largest string possible after some number of swaps.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;10&quot;
<strong>Output:</strong> &quot;10&quot;
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 50</code></li>
	<li><code>s[i]</code> is either <code>&#39;0&#39;</code> or <code>&#39;1&#39;</code>.</li>
	<li><code>s</code> is a special binary string.</li>
</ul>

bool cmp(const string& s1, const string& s2) { return s1 + s2 > s2 + s1; }
class Solution {
 public:
  string makeLargestSpecial(string s) {
    if (s.size() <= 2) return s;
    int balance = 0, start = 0;
    vector<string> subs;
    for (int i = 0; i < s.size(); i++) {
      balance += (s[i] - '0' == 0) ? -1 : 1;
      if (balance == 0) {
        subs.emplace_back(s.substr(start, i - start + 1));
        start = i + 1;
      }
    }
    for (int i = 0; i < subs.size(); i++) {
      subs[i] = '1' + makeLargestSpecial(subs[i].substr(1, subs[i].size() - 2)) + '0';
    }
    sort(subs.begin(), subs.end(), cmp);
    string ret = subs[0];
    for (int i = 1; i < subs.size(); i++) {
      ret += subs[i];
    } //Code With Avinash
    return ret;
  }
};
9700