We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
lefts='{[('rights='}])'closes={a:bfora,binzip(rights,lefts)}defvalid(s):stack=[]forcins:ifcinlefts:stack.append(c)elifcinrights:ifnotstackorstack.pop()!=closes[c]:returnFalsereturnnotstack# stack must be empty at the endt=int(raw_input().strip())fora0inxrange(t):s=raw_input().strip()ifvalid(s):print'YES'else:print'NO'
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
Python solution