✅ [Python3] DP Solution O(n) Time
\nclass Solution:\n    def minSwap(self, nums1: List[int], nums2: List[int]) -> int:\n        dp = [[-1]*2 for i in range(len(nums1))]\n        \n        def so
```\nclass Solution:\n    def minSwap(self, nums1: List[int], nums2: List[int]) -> int:\n        dp = [[-1]*2 for i in range(len(nums1))]\n        \n        def solve(prev1, prev2, i, swaped):\n            if i >= len(nums1): return 0\n            if dp[i][swaped] != -1: return dp[i][swaped]\n                        \n            ans = 2**31\n            \n            # No Swap\n            if nums1[i] > prev1 and nums2[i] > prev2:\n                ans = solve(nums1[i], nums2[i], i+1, 0) \n            \n            # Swap\n            if nums1[i] > prev2 and nums2[i] > prev1:\n                ans = min(ans, 1 + solve(nums2[i], nums1[i], i+1, 1)) \n            \n            dp[i][swaped] = ans\n            return ans\n        \n        return solve(-1, -1, 0, 0)  \n```
['Dynamic Programming', 'Recursion', 'Memoization', 'Python', 'Python3']