Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Iterate over the string and keep track of the number of opening and closing brackets on each step.
If the number of closing brackets is ever larger, you need to make a swap.
Swap it with the opening bracket closest to the end of s.