FunctionRacerProblemsRace

Close Every Bracket

BeginnerStacks and queuesPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Stacks and queues problems