You are viewing a single comment's thread. Return to all comments →
This function counts the minimum number of operations required to make a binary string "beautiful" by replacing occurrences of '010' with '011'.
'010'
'011'
def beautifulBinaryString(b): count = 0 ans = 0 while count != 1: a = b.find('010') if a >= 0: b = b[:a+2] + '1' + b[a+3:] ans += 1 count += 0 else: count += 1 return ans
s = '0101010' print(beautifulBinaryString(s)) # Output: 2
find('010')
'0'
'1'
Seems like cookies are disabled on this browser, please enable them to open this website
Beautiful Binary String
You are viewing a single comment's thread. Return to all comments →
🧠Problem: Beautiful Binary String
This function counts the minimum number of operations required to make a binary string "beautiful" by replacing occurrences of
'010'
with'011'
.🧪 Example Usage
✅ Notes:
find('010')
method locates the first occurrence of the pattern.'0'
to'1'
.'010'
is found.