💥 Runtime beats 100.00%, Memory beats 66.67% [EXPLAINED]
Intuition\nImagine you\'re trying to make two sequences of numbers strictly increasing. You have two arrays, nums1 and nums2, and you can swap elements at the s
# Intuition\nImagine you\'re trying to make two sequences of numbers strictly increasing. You have two arrays, nums1 and nums2, and you can swap elements at the same index between these arrays. Your goal is to find the minimum number of swaps required to make both arrays strictly increasing.\n\nThink of it like organizing two rows of numbers so that each number is smaller than the one that comes after it. If you need to swap some numbers between the rows to achieve this, you want to minimize the number of swaps.\n\n# Approach\nStart Small:\n\nBegin with the first element. If it\'s not swapped, the number of swaps required is zero (dp0[0] = 0). If it\'s swapped, you\'ll need one swap (dp1[0] = 1).\n\nMove Step-by-Step:\n\nFor each subsequent element, decide whether to swap or not based on whether the current and previous numbers in both arrays are strictly increasing. You\'ll keep track of two things:\n\ndp0[i]: Minimum swaps needed up to index i without swapping the current index.\ndp1[i]: Minimum swaps needed up to index i with swapping the current index.\n\nUpdate Your Decisions:\n\nAt each step, update the minimum swaps required based on whether you swap or not:\n\nIf you don\'t swap, check if the previous element conditions are satisfied without swapping.\nIf you swap, check if the previous element conditions are satisfied with swapping.\n\nChoose the Best Option:\n\nAfter processing all elements, you\u2019ll have two possible values for the last index: either you didn\u2019t swap or you did. The result will be the minimum of these two values.\n\n# Complexity\n- Time complexity:\nO(n): The approach involves a single pass through the arrays (from the start to the end), making it linear in terms of time. For each element, we do constant-time work (checking and updating values).\n\n- Space complexity:\nO(n): We use arrays dp0 and dp1 to keep track of the minimum swaps up to each index. Since these arrays are of size n (the length of the input arrays), the space used is linear with respect to the number of elements.\n\n# Code\n```typescript []\nfunction minSwap(nums1: number[], nums2: number[]): number {\n    const n = nums1.length;\n    let dp0 = new Array(n).fill(Infinity); // Minimum swaps without swap at index i\n    let dp1 = new Array(n).fill(Infinity); // Minimum swaps with swap at index i\n\n    // Initialize for the first index\n    dp0[0] = 0;\n    dp1[0] = 1;\n\n    for (let i = 1; i < n; i++) {\n        const noSwap = nums1[i - 1] < nums1[i] && nums2[i - 1] < nums2[i];\n        const swap = nums1[i - 1] < nums2[i] && nums2[i - 1] < nums1[i];\n\n        if (noSwap) {\n            dp0[i] = Math.min(dp0[i], dp0[i - 1]);\n            dp1[i] = Math.min(dp1[i], dp1[i - 1] + 1);\n        }\n        \n        if (swap) {\n            dp0[i] = Math.min(dp0[i], dp1[i - 1]);\n            dp1[i] = Math.min(dp1[i], dp0[i - 1] + 1);\n        }\n    }\n\n    return Math.min(dp0[n - 1], dp1[n - 1]);\n}\n\n```
['TypeScript']