You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: DSA Crack Sheet/README.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -82,6 +82,7 @@
82
82
-[Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/"view question") - [Cpp Solution](./solutions/Longest%20Common%20Prefix.cpp)
83
83
-[Min Number of Flips](https://practice.geeksforgeeks.org/problems/min-number-of-flips/0#"view question") - [Cpp Solution](./solutions/Min%20Number%20of%20Flips.cpp)
84
84
-[Second most repeated string in a sequence](https://practice.geeksforgeeks.org/problems/second-most-repeated-string-in-a-sequence0534/1#"view question") - [Cpp Solution](./solutions/Second%20most%20repeated%20string%20in%20a%20sequence.cpp)
85
+
-[Minimum Swaps for Bracket Balancing](https://practice.geeksforgeeks.org/problems/minimum-swaps-for-bracket-balancing/0#"view question") - [Cpp Solution](./solutions/Minimum%20Swaps%20for%20Bracket%20Balancing.cpp)
You are given a string of 2N characters consisting of N ‘[‘ brackets and N ‘]’ brackets. A string is considered balanced if it can be represented in the for S2[S1] where S1 and S2 are balanced strings. We can make an unbalanced string balanced by swapping adjacent characters. Calculate the minimum number of swaps necessary to make a string balanced.
6
+
7
+
Input:
8
+
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains an integer N denoting the length of the string.
9
+
10
+
The second line of each test case contains the string consisting of '[' and ']'.
11
+
12
+
Output:
13
+
Print the minimum number of swaps to make the string balanced for each test case in a new line.
0 commit comments