Close Every Bracket
s is made only of opening brackets of three kinds: (, [ and {. Return the shortest string of closing brackets that, written after s, closes every bracket properly: the bracket opened last must be closed first, and each one must be closed by the closing bracket of its own kind.
For s = "([{" the answer is "}])". Return "" when s is empty.
Example 1
s "([{"
returns "}])"
{ was opened last so it closes first, then [, then (.
Example 2
s "(("
returns "))"
Two round brackets need two round closers.
Constraints
0 <= len(s) <= 60scontains only(,[and{
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Stacks and queues problems
- Crate PileBeginner
- Dead-End DrivewayBeginner
- Elevator TripsBeginner
- Flip the PancakesBeginner
- Last In, First OutBeginner
- Notes on the BoardBeginner
- One-Bay Car WashBeginner
- Round the QueueBeginner