class Solution:
def makeLargestSpecial(self, s: str) -> str:
"""tc O(N^2) sc O(N)
1. keep counting current 1 until cnt == 0, we find partition point,
2. push substring into stack
3. after loop is over, sort the substring and get lexicographically largest largest string
"""
cnt,res = 0, []
l = 0
split= 0
for r in range(len(s)):
if s[r] == '1':
cnt += 1
else:
cnt -= 1
if cnt == 0:
split += 1
res.append('1'+ self.makeLargestSpecial(s[l+1:r]) + '0') # put sorted substring into res
l = r + 1
#print(len(res),split) # len === split
return ''.join(sorted(res,reverse=True))