C++ DP O(N) Time and O(1) space solution
\nclass Solution {\npublic:\n  int minSwap(vector<int> &one, vector<int> &two)\n  {\n    int n = one.size();\n    int swap = 1;\n    int noSwap = 0;\n\n    for 
```\nclass Solution {\npublic:\n  int minSwap(vector<int> &one, vector<int> &two)\n  {\n    int n = one.size();\n    int swap = 1;\n    int noSwap = 0;\n\n    for (int i = 1; i < n; i++)\n    {\n      int oldSwap = swap;\n      int oldNoSwap = noSwap;\n\n      if (one[i] > one[i - 1] and one[i] > two[i - 1] and two[i] > two[i - 1] and two[i] > one[i - 1])\n      {\n        swap = 1 + min(oldSwap, oldNoSwap);\n        noSwap = min(oldSwap, oldNoSwap);\n      }\n      else if (one[i] <= one[i - 1] or two[i] <= two[i - 1])\n      {\n        swap = 1 + oldNoSwap;\n        noSwap = oldSwap;\n      }\n      else if (one[i] > one[i - 1] and two[i] > two[i - 1] and (one[i] <= two[i - 1] or two[i] <= one[i - 1]))\n      {\n        swap = 1 + oldSwap;\n        noSwap = oldNoSwap;\n      }\n    }\n    return min(swap, noSwap);\n  }\n};\n```
['Dynamic Programming', 'C']