about | help | code help+videos | done | prefs |
Write a function that takes as input a string that may contain some parentheses, and returns a version of the string with balanced parentheses, formed by adding the minimum number of parens, and otherwise leaving the string unchanged. In general, there are several possible ways to do this. For example, the string "((" could be balanced as "(())" or as "()()". For the purpose of this exercise, do it so that the missing parens are added at the last possible position in the string; that is, as far right as possible, so that we would chose "(())". balance_parens('((') → '(())' balance_parens('(x + 1') → '(x + 1)' balance_parens('(x * (x - 1') → '(x * (x - 1))' ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Copyright Nick Parlante 2017 - privacy