Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Problem 1303. Is the paranthesis sequence balanced ?

Created by Muthu Annamalai

Quantum mechanics and computer science are interested in bra-kets. Today however you, the player, will have to write a function to find if the given parenthesis expression is balanced.

e.g.

>> balance('(()()())')
   1
>> balance('(()()())(') 
   0
>> balance('(())))()())')
   0
>> balance('(((()))((())))')
   1

Hint: consider using a stack. Review your basic data structures for ideas.

Problem Group

Solution Statistics

53 correct solutions 29 incorrect solutions
Last solution submitted on Sep 11, 2014