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