C++ || DP || MEMOIZATION DP
REC + MEMO\n\nclass Solution {\npublic:\n    int solve(vector<int>& nums1, vector<int>& nums2 ,  int index ,  int swapped ,  vector<vector<int>> &dp){\n\n      
REC + MEMO\n```\nclass Solution {\npublic:\n    int solve(vector<int>& nums1, vector<int>& nums2 ,  int index ,  int swapped ,  vector<vector<int>> &dp){\n\n        // base case \n        if(index ==  nums1.size()){\n            return 0 ;\n        }\n\n        int ans =  INT_MAX ;\n        int prev1 =  nums1[index-1] ;\n        int prev2 =   nums2[index-1 ];\\\n\n        if(dp[index][swapped] != -1){\n            return dp[index][swapped] ;\n        }\n\n        if(swapped){\n            swap(prev1 , prev2) ;\n\n        }\n\n        // NO SWAPP\n        if(nums1[index] > prev1 && nums2[index] >prev2){\n            ans =  solve(nums1 , nums2 , index+1 , 0 , dp);\n        }\n\n        // SWAPPED\n        if(nums1[index] > prev2  && nums2[index] > prev1){\n            ans = min(ans ,  1+solve(nums1 , nums2 , index+1 , 1,dp)) ;\n        }\n        return dp[index][swapped] = ans ;\n    }\n\n    int minSwap(vector<int>& nums1, vector<int>& nums2) {\n\n        // st1 : add -1 at the begninng of both the arrays \n        nums1.insert(nums1.begin() , -1);\n        nums2.insert(nums2.begin() , -1);\n        int n =  nums1.size() ;\n        bool swapped =  0 ;\n\n        vector<vector<int>> dp(n , vector<int> (2,-1)) ;\n        return solve(nums1, nums2 , 1 , swapped , dp);        \n    }\n};\n```
['Dynamic Programming', 'C', 'C++']