Recursion || C++
\n// We have two choices either swap ith or don\'t swap ith since we want increasing order so if ith is in increasing order then we can choose not to swap and i
```\n// We have two choices either swap ith or don\'t swap ith since we want increasing order so if ith is in increasing order then we can choose not to swap and if swapping them also result in increasing then we can choose to swap.\n\nclass Solution {\npublic:\n    vector<vector<int>>dp;\n    int minSwap(vector<int>& nums1, vector<int>& nums2) {\n        \n        // appending -1 in nums1 and nums2 for convinience instead of appending we can call min(first swapped, first unswapped)\n        nums1.insert(nums1.begin(),-1);             \n        nums2.insert(nums2.begin(),-1);\n        \n        dp.resize(nums1.size(),vector<int>(2,-1));\n        return solve(1,0,nums1,nums2);\n    }\n    \n    int solve(int i,bool swapped,vector<int>&nums1,vector<int>&nums2){\n        \n        if(i==nums1.size()) return 0;\n        if(dp[i][swapped]!=-1) return dp[i][swapped];\n        \n        int ans=INT_MAX;\n        int pre1=nums1[i-1],pre2=nums2[i-1];\n        if(swapped){                                // if previous one is swapped\n            swap(pre1,pre2);\n        }\n        \n        if(nums1[i]>pre1 && nums2[i]>pre2){         // choice 1 we don\'t swap if it is in increasing\n            ans=solve(i+1,0,nums1,nums2);\n        }\n        \n        if(nums1[i]>pre2 && nums2[i]>pre1){         // choice 2 we swap if swapping result in increasing order\n            ans=min(ans,solve(i+1,1,nums1,nums2)+1);\n        }\n        \n        return dp[i][swapped]=ans;\n        \n    }\n};\n```\n\n// https://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing/discuss/262241/Recursive-with-memoization-(beats-100.00-):
['Recursion', 'C']