💢☠💫Easiest👾Faster✅💯 Lesser🧠 🎯 C++✅Python3🐍✅Java✅C✅Python🐍✅C#✅💥🔥💫Explained☠💥🔥 Beats 100
Intuition\n\n Describe your first thoughts on how to solve this problem. \n- JavaScript Code --> https://leetcode.com/problems/minimum-number-of-swaps-to-make-t
# Intuition\n![0ehh83fsnh811.jpg](https://assets.leetcode.com/users/images/4cf36d32-d174-4566-b1f8-5caa8d0ab951_1728398473.3444586.jpeg)\n<!-- Describe your first thoughts on how to solve this problem. -->\n- ***JavaScript Code -->*** https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-string-balanced/submissions/1415951145\n- ***C++ Code -->*** https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-string-balanced/submissions/1415634253\n- ***Python3 Code -->*** https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-string-balanced/submissions/1415889759\n- ***Java Code -->*** https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-string-balanced/submissions/1415851639\n- ***C Code -->*** https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-string-balanced/submissions/1415940362\n- ***Python Code -->*** https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-string-balanced/submissions/1415862639\n- ***C# Code -->*** https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-string-balanced/submissions/1415942939\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n     O(N)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n     O(1)\n# Code\n```javascript []\n/**\n * @param {string} s\n * @return {number}\n */\nvar minSwaps = function(s) {\n    let cnt = 0\n    for (let i = 0; i < s.length; ++i) {\n        if (s[i] === "[")\n            cnt += 1\n        else if (cnt > 0)\n            cnt  -= 1\n    }\n    return Math.floor((cnt + 1) / 2)\n};\n```\n![th.jpeg](https://assets.leetcode.com/users/images/e11a721a-e48a-44f1-b2be-89a966e4b75e_1728398829.8510702.jpeg)\n
['Two Pointers', 'String', 'Greedy', 'C', 'C++', 'Java', 'JavaScript']