Java ||Recursion and  Memoization Solution || clears understanding
```\nclass Solution {\n   \n   int [][] dp;\n    public int minSwap(int[] nums1, int[] nums2) {\n        List list1 = new ArrayList<>();\n        \n        for(
```\nclass Solution {\n   \n   int [][] dp;\n    public int minSwap(int[] nums1, int[] nums2) {\n        List<Integer> list1 = new ArrayList<>();\n        \n        for(int x : nums1)\n        {\n            list1.add(x);\n        }\n        list1.add(0,-1);\n        \n        List<Integer> list2 = new ArrayList<>();\n        for(int x : nums2)\n        {\n            list2.add(x);\n        }\n        list2.add(0,-1);\n        \n        dp = new int[list1.size()][2];\n        for(int []arr: dp)\n        {\n            Arrays.fill(arr,-1);\n        }\n     \n        return solve(list1,list2, 1,0);\n    \n    }\n    \n    public int solve(List<Integer> list1, List<Integer> list2,int index ,  int swapped )\n    {\n        if(index==list1.size())\n        {\n            return 0; \n        }\n        \n        if(dp[index][swapped]!=-1)\n        {\n            return dp[index][swapped];\n        }\n          \n        int prev1 = list1.get(index-1);\n        int prev2 = list2.get(index-1);\n            \n      \n        if(swapped==1)\n        {\n            int temp=prev1;\n            prev1=prev2;\n            prev2=temp;\n        }\n        \n       // first option : dont swap the values \n        int ans = Integer.MAX_VALUE;\n        if(prev1 < list1.get(index) && prev2< list2.get(index))\n        {\n            ans= solve(list1, list2, index+1,0);\n        }\n    \n        // second option :swap the values\n         if(prev1 < list2.get(index) && prev2< list1.get(index))\n         {\n              ans =Math.min(ans,1 + solve(list1,list2, index+1, 1));\n         }\n      \n        return dp[index][swapped]= ans;\n    }\n}
['Java']