Clear Python o(n) Time, o(n) Space solution with comments
bottom up dp python solution with comments\n\nTime: o(n)\nSpace: o(n)\n\n\n\nclass Solution:\n    def minSwap(self, A: List[int], B: List[int]) -> int:\n       
bottom up dp python solution with comments\n\nTime: o(n)\nSpace: o(n)\n\n\n```\nclass Solution:\n    def minSwap(self, A: List[int], B: List[int]) -> int:\n        \n        n = len(A)\n        \n        # In this problem, we have two states that we need to keep track at element i; \n        # what happens if we swap or do not swap at i?\n        \n        # min number of swaps to get ascending order if we SWAP at i             \n        swap = [0] * n\n        \n        # min number of swaps to get ascending order if we do NOT SWAP at i\n        noswap = [0] * n\n        \n        # base case: swapping 0th element\n        swap[0] = 1\n\n        for i in range(1, n):\n            strictly_increasing = A[i] > A[i-1] and B[i] > B[i-1]\n            strictly_xincreasing = A[i] > B[i-1] and B[i] > A[i-1]\n            \n            # we can swap here, but we also do not have too\n            if strictly_increasing and strictly_xincreasing:                               \n                \n                # if we decide to swap at i, we can consider the state of either swapping or not swapping i-1, since doing either\n                # will not break out strictly increasing for either array rule\n                swap[i] = min(noswap[i-1], swap[i-1]) + 1\n                \n                # we chose not to swap at i, so we can consider states if we swap at i - 1 or not swap, since again we will not break the strictly                          increasing rule\n                noswap[i] = min(noswap[i-1], swap[i-1])\n                \n            \n            # we can not swap at i, since we know that A[i] is not greater than B[i-1], or that B[i] is not greater than A[i-1]\n            elif strictly_increasing:\n                \n                \n                \n                # if we swap at i, then to keep increasing condition, we must also swap at i-1, we are essentially just swapping both i and i-1 and get                     the same thing \n                swap[i] = swap[i-1] + 1\n                \n                # if we do not swap at i, then we must also chose to not swap at i-1 to keep the problem conditions true\n                noswap[i] = noswap[i-1]\n                \n              \n            # we must swap, since A[i] is not greater than A[i-1], or B[i] is not greater than B[i-1]\n            # but we know that A[i] > B[i-1] and that B[i] > A[i-1]\n            elif strictly_xincreasing:\n\n                # if we swap at i, then we must have not swapped at i-1\n                swap[i] = noswap[i-1] + 1\n                \n                # if we do not swap at i, then we must have swapped at i-1 for the problem conditions to be true\n                noswap[i] = swap[i-1]\n                \n            \n        \n        # take min of both state paths to see who holds the better result\n        return min(noswap[n-1], swap[n-1])\n\n\n```
['Dynamic Programming', 'Python3']