C++ DP Solution [Tabulation]
\nclass Solution {\npublic:\n    int minSwap(vector<int>& nums1, vector<int>& nums2) {\n        \n        int n = nums1.size();\n        \n        vector<vector
```\nclass Solution {\npublic:\n    int minSwap(vector<int>& nums1, vector<int>& nums2) {\n        \n        int n = nums1.size();\n        \n        vector<vector<int>> dp(n, vector<int>(2,-1));\n        \n        dp[0][0] = 0;\n        dp[0][1] = 1;\n        \n      \n        \n        for(int i=1;i<n;i++) {\n            \n            bool a = (nums1[i-1] < nums1[i] && nums2[i-1] < nums2[i]);        \n            bool b = (nums1[i-1] < nums2[i] && nums2[i-1] < nums1[i]);\n            \n            if(a && b) {\n                dp[i][0] = min(dp[i-1][0] , dp[i-1][1]) ;\n                dp[i][1] = min(dp[i-1][0], dp[i-1][1]) + 1;\n            }\n            else if(a) {\n                dp[i][0] = dp[i-1][0];\n                dp[i][1] = dp[i-1][1] + 1;\n                \n            }\n            else {\n                dp[i][0] = dp[i-1][1];\n                dp[i][1] = dp[i-1][0] + 1;\n                \n            }\n        }\n        \n        return min(dp[n-1][0], dp[n-1][1]);\n        \n    }\n};\n```
['Dynamic Programming', 'C']