Java with explanation. DFS + Memoization. SC: O(N), TC: O(N)
\n# Code\n\nclass Solution {\n    Integer[][] memo;\n    int SWAPPED = 0;\n    int NOT_SWAPPED = 1;\n\n    int NOT_VALID = (int) Math.pow(10, 6);\n    public in
\n# Code\n```\nclass Solution {\n    Integer[][] memo;\n    int SWAPPED = 0;\n    int NOT_SWAPPED = 1;\n\n    int NOT_VALID = (int) Math.pow(10, 6);\n    public int minSwap(int[] nums1, int[] nums2) {\n        this.memo = new Integer[nums1.length][2];\n        return dfs(nums1, nums2, 0, NOT_SWAPPED);\n    }\n\n    private int dfs(int[] nums1, int[] nums2, int index, int swapped) {\n        if (index == nums1.length) return 0;\n\n        if (memo[index][swapped] != null) return memo[index][swapped];\n\n        // we have 2 option: 1) swap our arr[index] or not\n        int option1 = NOT_VALID;\n        // before proceed any option check: is it valid? \n        // Is arr[i] > arr[i-1]?\n        if (isValidOption(nums1, nums2, index)) {\n            // we didn\'t swapped our arr[i], amount of operations the same\n            option1 = dfs(nums1, nums2, index + 1, NOT_SWAPPED);\n        }\n\n        // swap, dfs and swap again\n        swap(nums1, nums2, index);\n        int option2 = NOT_VALID;\n        if (isValidOption(nums1, nums2, index) && nums1[index] != nums2[index]) {\n            // we swapped our arr[i], amount of operations increased by 1\n            option2 = dfs(nums1, nums2, index + 1, SWAPPED) + 1;\n        }\n        swap(nums1, nums2, index);\n\n        // take the minimum amount of operations\n        int result = Math.min(option1, option2);\n        \n        // we have 2 ways to save data:\n        // if our PREVIOUS index was swapped hold 0, opposite 1\n        memo[index][swapped] = result;\n        return result;\n    }\n\n    private boolean isValidOption(int[] nums1, int[] nums2, int index) {\n        if (index == 0) return true;\n        return nums1[index] > nums1[index - 1] && nums2[index] > nums2[index - 1];\n    }\n\n\n    private void swap(int[] arr1, int[] arr2, int i) {\n        int temp = arr1[i];\n        arr1[i] = arr2[i];\n        arr2[i] = temp;\n    }\n}\n```
['Java']