Python O(n) time, O(1) space
\npython3 []\nclass Solution:\n    def minSwap(self, nums1: List[int], nums2: List[int]) -> int:\n        dp = [0, 1]\n\n        for i in range(1, len(nums1)):\
\n```python3 []\nclass Solution:\n    def minSwap(self, nums1: List[int], nums2: List[int]) -> int:\n        dp = [0, 1]\n\n        for i in range(1, len(nums1)):\n            noSwap, yesSwap = 0, 0\n\n            # check valid configurations\n            if (nums1[i-1] >= nums1[i]) or (nums2[i-1] >= nums2[i]): \n                noSwap = dp[1]      # prev must be swapped if not swapping cur\n                yesSwap = dp[0] + 1 # prev cannot be swapped if swapping cur\n            elif (nums1[i-1] >= nums2[i]) or (nums2[i-1] >= nums1[i]):\n                noSwap = dp[0]      # prev cannot be swapped if not swapping cur\n                yesSwap = dp[1] + 1 # prev must be swapped if swapping cur\n            else:\n                noSwap = min(dp[0], dp[1])\n                yesSwap = min(dp[0], dp[1]) + 1\n\n            dp = [noSwap, yesSwap]\n        return min(dp)\n```
['Python3']