Don't use stack in interviews, simple explanation, added YouTube video
YouTube solution https://youtu.be/iX8_V3266co\n\n# Intuition and approach\nlets keep things super simple, we would just traverse through string from left to rig
# YouTube solution https://youtu.be/iX8_V3266co\n\n# Intuition and approach\nlets keep things super simple, we would just traverse through string from left to right \nlet say we have **int open = 0**\n\n=> whenever we are getting an open bracket then \n        **open++;**\n=> but if we are encountring with **close bracket then** -->\n   a) if open>0 then dcrease open ==> **open--**\n   b) else keep on traversing .\n\n**now you might have a question but what is the intention here??**\n\nsimple, if we found a open bracket we are doing open++ and if we found a close bracket then we have to check if **open>0** because then only we can say that there is already an open bracket to balance this closing bracket so do **open--** because this will pair with occured close bracket to make balance part.\n\nlike this highlighted part=>  ]]**[]**[[\nif traverse throgh obove string ==> "]][][["\n\nfor i = 0; to i<6\n at i = 0 ==> open = 0\n    i = 1 ==> open = 0\n    i = 2 ==> open = 1\n    i = 3 ==> open = 0 **(a close bracket found and open decresed)**\n    i = 4 ==> open = 1\n    i = 5 ==> open = 2\n\nnow we have to return **(open+1)/2** this will give us number of min swaps required.\n\n**how can you i say that, right there should be a proof it??**\n\nwell so as per given in the question in balanced bracket pair an **equal numbers of brackets ar consumed**\n\nso whatever value we have in **open** there must be an equal number of closing brackets as well that we need to make them balance by min swaps, right?\n\n==> so one swap consumes 2 more brackets as part of balanced string=>\n**]**]][[ **[** ==> we swap first and last ==> []][[] ====> one more swap of two middle open close ==> [][][].\n\ntotal = 2 operations.\n\nwe had open = 3 ===> (3+1)/2 = 2  \nso we have to that is why should return (open+1)/2\n\n**still problem? no problem soon i would release youtube video**           \n\n\n\n\n\n\n\n\n# Complexity\nTime Complexity => O(n)\nSpace Complexity => O(1)\n\n# Code\n```java [] approach 1 =====>\nclass Solution {\n    public int minSwaps(String s) {\n    int open = 0; \n    for(int i=0; i<s.length(); i++)\n    {\n      if(s.charAt(i)==\'[\')open++;\n      else\n      {\n        if(open>0)open--;\n      }  \n    }        \n     return (open+1)/2;\n    }\n}\n\n```java [] approach 2========>\n \nclass Solution {\n    public int minSwaps(String s) {\n    int open = 0;\n    int mismatch = 0;     \n    for(int i=0; i<s.length(); i++)\n    {\n      char ch = s.charAt(i);\n      if(ch==\'[\')\n      {\n        open++;\n      }\n        else{\n            if(open>0)\n            {\n              open--; \n            }\n            else\n                mismatch++; \n        }\n    }\n     int n = open + mismatch;\n     int ans = 0; \n     while(n>0)\n     {\n      ans++;\n         n = n-4; \n     }\n        return ans; \n    }\n}\n```
['String', 'String Matching', 'Java', 'C#']