C++ || Easy using stack ✅✅
Intuition\nThe problem requires balancing the brackets using the minimum number of swaps. A valid configuration should have each closing bracket ] matched by a 
# Intuition\nThe problem requires balancing the brackets using the minimum number of swaps. A valid configuration should have each closing bracket `]` matched by a preceding opening bracket `[`. The core idea is to count how many unmatched `[` and `]` there are, and perform swaps to balance them.\n\n# Approach\n1. Use a stack to keep track of unmatched opening brackets `[`.\n2. Traverse the string:\n   - If the current character is `]` and the stack is empty, we continue (since it\u2019s an unbalanced `]` and we can potentially match it later).\n   - If the current character is `]` and there is an unmatched `[` on top of the stack, we pop the stack (indicating that the `]` found a matching `[`).\n   - Otherwise, if the current character is `[`, push it onto the stack (indicating a potential unmatched `[`).\n3. At the end of the traversal, the size of the stack will represent the number of unmatched `[` brackets.\n4. The minimum number of swaps required to balance the string is `(st.size() + 1) / 2` since each swap corrects two unbalanced brackets.\n\n# Complexity\n- **Time complexity**:  \n  The time complexity is $$O(n)$$, where `n` is the length of the string. We traverse the string once, and each stack operation (push and pop) is performed in constant time.\n  \n- **Space complexity**:  \n  The space complexity is $$O(n)$$ in the worst case, where all characters are opening brackets `[`, and the stack grows to size `n`.\n\n# Code\n```cpp\nclass Solution {\npublic:\n    int minSwaps(string s) {\n        stack<char> st;\n        for(int i = 0; i < s.length(); i++) {\n            if(s[i] == \']\' && st.empty()) {\n                continue;\n            }\n            else if(s[i] == \']\' && st.top() == \'[\') {\n                st.pop();\n            }\n            else {\n                st.push(\'[\');\n            }\n        }\n        return (st.size() + 1) / 2;\n    }\n};\n
['Stack', 'Monotonic Stack', 'C++']