A graspable recursive solution
\nclass Solution {\n    public int minSwap(int[] nums1, int[] nums2) {\n        Map<String, Integer> memo = new HashMap<>();\n        return Math.min(dfs(nums1,
```\nclass Solution {\n    public int minSwap(int[] nums1, int[] nums2) {\n        Map<String, Integer> memo = new HashMap<>();\n        return Math.min(dfs(nums1, nums2, 1, false, memo), \n                        dfs(nums1, nums2, 1, true, memo) + 1);\n    }\n    \n    private int dfs(int[] nums1, int[] nums2, int index, boolean prevSwap, Map<String, Integer> memo){\n        if(index == nums1.length){\n            return 0;\n        }\n        \n        int a = nums1[index - 1];\n        int b = nums2[index - 1];\n        \n        if(prevSwap){\n            a = nums2[index - 1];\n            b = nums1[index - 1];\n        }\n        \n        String key = index + ":" + prevSwap;\n        if(memo.containsKey(key)){\n            return memo.get(key);\n        }\n        \n        int res = Integer.MAX_VALUE;\n        \n        if(nums1[index] > a && nums2[index] > b){\n            res = Math.min(res, dfs(nums1, nums2, index + 1, false, memo));\n        }\n        \n        if(nums1[index] > b && nums2[index] > a){\n            res = Math.min(res, dfs(nums1, nums2, index + 1, true, memo) + 1);\n        }\n        \n        memo.put(key, res);\n        return res;\n    }\n}\n```
['Recursion', 'Memoization']