[Python3] two counters
Algo \nThis solution is different from the mainstream solutions. Given that we know a solution exists, if we put larger of A[i] and B[i] to A and smaller of A[i
Algo \nThis solution is different from the mainstream solutions. Given that we know a solution exists, if we put larger of `A[i]` and `B[i]` to `A` and smaller of `A[i]` and `B[i]` to `B`. The resulting sequence satisfies the requirement of increasing `A` and increasing `B`. In the spirit of this idea, we can count the occurrence of `A[i] < B[i]` in `sm` and count the occurrence of `A[i] > B[i]` in `lg`. The minimum of `sm` and `lg` gives enough swap to get two increasing sequences. The issue is that it is more than enough as there can be cases where `max(A[i-1], B[i-1]) < min(A[i], B[i])`. In such a case, we treat the array as two subarrays ending at `i-1` and starting at `i`. The sum of all such pieces gives the correct answer. \n\nImplementation (72ms, 99.18%)\n```\nclass Solution:\n    def minSwap(self, A: List[int], B: List[int]) -> int:\n        ans = sm = lg = mx = 0\n        for x, y in zip(A, B): \n            if mx < min(x, y): # prev max < current min\n                ans += min(sm, lg) # update answer & reset \n                sm = lg = 0 \n            mx = max(x, y)\n            if x < y: sm += 1 # count "x < y"\n            elif x > y: lg += 1 # count "x > y"\n        return ans + min(sm, lg)\n```
['Python3']