Skip to content

Commit 2f769ba

Browse files
authored
Update special-binary-string.py
1 parent 8f11c6f commit 2f769ba

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

Python/special-binary-string.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
11
# Time: f(n) = k * f(n/k) + n/k * klogk <= O(logn * nlogk) <= O(n^2)
22
# n is the length of S, k is the max number of special strings in each depth
33
# Space: O(n)
4-
4+
5+
# Special binary strings are binary strings with the following two properties:
6+
#
7+
# The number of 0's is equal to the number of 1's.
8+
# Every prefix of the binary string has at least as many 1's as 0's.
9+
# Given a special string S, a move consists of choosing two consecutive, non-empty,
10+
# special substrings of S, and swapping them.
11+
# (Two strings are consecutive if the last character of the first string is
12+
# exactly one index before the first character of the second string.)
13+
#
14+
# At the end of any number of moves, what is the lexicographically largest resulting string possible?
15+
#
16+
# Example 1:
17+
# Input: S = "11011000"
18+
# Output: "11100100"
19+
#
20+
# Explanation:
21+
# The strings "10" [occuring at S[1]] and "1100" [at S[3]] are swapped.
22+
# This is the lexicographically largest string possible after some number of swaps.
23+
#
24+
# Note:
25+
# - S has length at most 50.
26+
# - S is guaranteed to be a special binary string as defined above.
27+
528
class Solution(object):
629
def makeLargestSpecial(self, S):
730
"""

0 commit comments

Comments
 (0)