| 1 | //User function Template for Java |
| 2 | class Solution{ |
| 3 | static int minimumNumberOfSwaps(String S){ |
| 4 | // code here |
| 5 | int open=0; |
| 6 | int close=0; |
| 7 | int swap=0; |
| 8 | int imbalance=0; |
| 9 | for(int i=0;i<S.length();i++) |
| 10 | { |
| 11 | if(S.charAt(i)=='[') |
| 12 | { |
| 13 | open++; |
| 14 | if(imbalance>0) |
| 15 | { |
| 16 | swap+=imbalance; |
| 17 | imbalance--; |
| 18 | } |
| 19 | } |
| 20 | else |
| 21 | { |
| 22 | close++; |
| 23 | imbalance=close-open; |
| 24 | } |
| 25 | } |
| 26 | return swap; |
| 27 | } |
| 28 | } |
nothing calls this directly
no outgoing calls
no test coverage detected