Python dp With Clear Explanation
Minimum swaps To make Sequences Increasing\n\n### Given 2 arrays, find minimum same indexed swaps that need to occur to make both arrays strictly increasing\n\n
## Minimum swaps To make Sequences Increasing\n\n### Given 2 arrays, find minimum same indexed swaps that need to occur to make both arrays strictly increasing\n\n1. Firstly, at each stage , we need to store the value of count if we swap A[i] and B[i] and if we don\'t swap A[i] and B[i].\n2. If they are increasing without a swap, then we don\'t need to do anything when we don\'t swap. We take the previous value stored for not swapping and store in current index. For swap, that means the swap which occurred previously was a faulty one , so we need to rectify that so swap[i-1] +1\n3. If they are increasing with a swap, that means B[i-1] < A[i] and A[i-1] < B[i]. This means if we want to swap A[i] and B[i], we can either keep[i-1] + 1 or swap[i-1] +1 (we can swap both or keep one and swap one . Both will work). We take the minimum of these two values. For noswap array, we take the minimum of swap[i-1] and noswap[i].\n4. In the end, the minimum of both final values (noswap and swap) are taken as the final result.\n\n```\nclass Solution:\n    def minSwap(self, A: List[int], B: List[int]) -> int:\n        n = len(A)\n        noswap = [ float(\'inf\')] * n\n        swap = [float(\'inf\')] * n\n        noswap[0] = 0\n        swap[0]=1\n        for i in range(1 , n):\n            incr_without_swap = A[i] >A[i-1] and B[i] >B[i-1]\n            incr_with_swap = A[i]>B[i-1] and B[i] > A[i-1]\n            if incr_without_swap:\n                #you can keep both values or swap both values\n                noswap[i]=noswap[i-1]\n                swap[i]= swap[i-1]+1\n            if incr_with_swap:\n                swap[i] = min(noswap[i-1] +1,swap[i])\n                noswap[i]= min(swap[i-1],noswap[i])\n        return min(noswap[-1],swap[-1])\n```
[]