Python | DP | Memoization | Simplest Solution With Explanation
Logic\n1. Instead of checking everytime the entire array to be strictly increasing, we could check at each index whether the element is greater than its previou
### Logic\n1. Instead of checking everytime the entire array to be strictly increasing, we could check at each index whether the element is greater than its previous index or not. If it is then the array is strictly increasing till this index.\n2. So if the index reaches the end of array it means the array is strictly increasing.\n3. Now for each index, \n\t- We will check whether the element at the current index for both the arrays can be swapped or not. If it can be swapped then we have one swap and then we can recur for further indexes.\n\t- We also need to check whether can we go for further recurrence without swapping\n4. The minimum of above two scenarios would be the answer.\n\n```\nclass Solution:    \n    def dp(self, nums1, nums2, prev1, prev2, i, swapped, lookup):\n        if i == len(nums1):\n            return 0\n        \n        key = (i, swapped)\n        if key not in lookup:\n            minSwaps = sys.maxsize\n            # Swap\n            if nums2[i] > prev1 and nums1[i] > prev2:\n                minSwaps = 1 + self.dp(nums1, nums2, nums2[i], nums1[i], i+1, 1, lookup)\n            # Dont swap\n            if nums2[i] > prev2 and nums1[i] > prev1:\n                minSwaps = min(minSwaps, self.dp(nums1, nums2, nums1[i], nums2[i], i+1, 0, lookup))\n            lookup[key] = minSwaps\n        return lookup[key]\n    \n    def minSwap(self, nums1: List[int], nums2: List[int]) -> int:\n        return self.dp(nums1, nums2, -1, -1, 0, 0, {})\n        \n```\n\n***If you liked the above solution then please upvote!***
['Dynamic Programming', 'Memoization', 'Python']