Question DSA-STK-0009
MediumWhat is the output of this code?
def ok(s):
st, pairs = [], {")": "(", "]": "[", "}": "{"}
for ch in s:
if ch in "([{":
st.append(ch)
elif not st or st.pop() != pairs[ch]:
return False
return not st
print(ok("({[]})"), ok("([)]"))
- A.
True True
- B.
False False
- C.
Sign up free to see the answer and a step-by-step explanation.