Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
All possible combinations solution in Clear category for Remove Brackets by Stensen
from itertools import combinations
def is_balanced(t, _t=None):
while t != _t: _t, t = t, t.replace('()', '').replace('{}', '').replace('[]', '')
return not t
def remove_brackets(line):
for i in range(len(line)):
for m in combinations(range(len(line)), i):
if is_balanced(cm := ''.join(k for j, k in enumerate(line) if j not in m)): return cm
return ''
Oct. 6, 2020
Comments: