C++ | O( N ) | Detailed Explanation and comments
Credits to : lee215\nI will be explaining the approach here.\n swap[i]  = total no. of swaps required to keep array from 0 to i in increasing order when we swap
Credits to : [lee215](https://leetcode.com/lee215)\nI will be explaining the approach here.\n* swap[i]  = total no. of swaps required to keep array from 0 to i in increasing order when we swap the ith positions\n* notswap[i]  = total no. of swaps required to keep array from 0 to i in increasing order when we do not  swap the ith positions\n\nIf condition (  A [ i ] > A [ i - 1]   & &   B [ i ]> B [ i - 1 ] )   is satisfied then \n* if we swap ith and we have to swap i-1 th also.\n* if we do not swap ith and we can not swap i-1 th also.\n\nIf condition (  A [ i ] > B [ i - 1 ]   &&   B [ i ]> A [ i - 1 ]   )    is satisfied then \n* if we swap ith then we can not  swap i-1 th.\n* if we do not swap ith then we have to  swap i-1 th.\n\nThe two conditions can be met simuntaneously for a given i.\n( It is not a if and else ) that is why in second if we have min to keep the minimum obtained for swap[i] and notswap[i] on following these two conditions.\n\n\n```\nclass Solution {\npublic:\n    int minSwap(vector<int>& A, vector<int>& B) {\n        int n = A.size();\n        vector<int>notswap(n);\n        vector<int>swap(n,1);\n        for(int i=1;i<n;i++){\n            swap[i]=n;\n            notswap[i]=n;\n            if(A[i]>A[i-1] && B[i]>B[i-1]){\n\t\t\t\t//swapped i so cant swap at i-1 hence notswap[i-1] and add one for swap at i\n                swap[i] = swap[i-1]+1;\n\t\t\t\t//not swapped at i so can do at i-1 also hence notswap[i]=notswap[i-1];\n                notswap[i]=notswap[i-1];\n            }\n\t\t\t // we take min just to get min out of thsese two if conditions\n            if(A[i]>B[i-1] && B[i]>A[i-1]){\n\t\t\t\t// swap at i so cant swap at i-1  hence notswap[i-1] and add one for swap at i\n                swap[i] = min(notswap[i-1]+1,swap[i]);\n\t\t\t\t//notswap[i] so we have to swap at i-1 hence swap[i-1] add zero for no swap at i\n                notswap[i]= min(swap[i-1],notswap[i]);\n            }\n        }\n        return min({swap[n-1],notswap[n-1]});\n    }\n};\n```
[]