c++ 98% dp. easy to explain and impl in 10mins. cheers!
\n#include <vector>\n#include <limits>\n\nusing namespace std;\n\nconst int INF = 1e5;\n\nclass Solution {\npublic:\n    int minSwap(vector<int>& A, vector<int>
```\n#include <vector>\n#include <limits>\n\nusing namespace std;\n\nconst int INF = 1e5;\n\nclass Solution {\npublic:\n    int minSwap(vector<int>& A, vector<int>& B) {\n        if (A.empty()) {\n            return 0;\n        }\n        \n        int n = A.size();\n        \n        vector<vector<int>> dp(n, vector<int>(2, INF));\n        dp[0][0] = 0;\n        dp[0][1] = 1;\n        for (int i = 1; i < n; ++i) {\n            if (A[i] > A[i - 1] && B[i] > B[i - 1]) {\n                dp[i][0] = min(dp[i][0], dp[i - 1][0]);\n                dp[i][1] = min(dp[i][1], dp[i - 1][1] + 1);\n            }\n            if (A[i] > B[i - 1] && B[i] > A[i - 1]) {\n                dp[i][0] = min(dp[i][0], dp[i - 1][1]);\n                dp[i][1] = min(dp[i][1], dp[i - 1][0] + 1);\n            }\n        }\n        \n        return min(dp[n - 1][0], dp[n - 1][1]);\n    }\n};\n\n\n```
[]