Super Intuitive solution(recursive + memoization)
\nclass Solution {\n    public int minSwap(int[] A, int[] B) {\n          Integer[][] dp = new Integer[A.length][2];//0 no swap, 1:swap\n\n          return dfs(
```\nclass Solution {\n    public int minSwap(int[] A, int[] B) {\n          Integer[][] dp = new Integer[A.length][2];//0 no swap, 1:swap\n\n          return dfs(A,B,0,dp,0);\n        }\n        public int dfs(int[] A,int[] B, int i,Integer[][] dp,int swap){\n\n          if(i==A.length){\n            return 0;\n          }\n          if(dp[i][swap]!=null)\n            return dp[i][swap];\n          int min1=Integer.MAX_VALUE;\n          if(i==0 || A[i] > A[i-1] && B[i] > B[i-1]){\n            min1=dfs(A,B,i+1,dp,0);\n          }\n          int min2=Integer.MAX_VALUE;\n          if(i==0 || A[i] > B[i-1] && B[i] >A[i-1]){\n            swap(A,B,i);\n            min2=dfs(A,B,i+1,dp,1)+1;\n            swap(A,B,i);\n          }\n          dp[i][swap]=Math.min(min1,min2);\n          return dp[i][swap];\n        }\n        public void swap(int[] A,int[] B, int idx){\n          int temp=A[idx];\n          A[idx]=B[idx];\n          B[idx]=temp;\n        }\n}\n```
[]