Fiksu Interview Question

Algorithm based question. FInding balanced paranthesis

Interview Answers

Anonymous

Dec 6, 2013

To find balanced parens, you need to set two parameters, the number of open parens must be greater than or equal the number of closed parens while parsing the string, and by the end, the number of open and closed parens must be equal. python solution: def balanced(parens): count_open = 0 count_closed = 0 for paren in parens: if paren == '(': count_open += 1 else count_close += 1 if count_open < count_closed: return False if count_open != count_closed return False return True

Anonymous

Sep 11, 2015

You can do it with one counter.