✅✅C++ || Recursive (MEMORIZED SOLUTION) || TOP DOWN
\nclass Solution {\npublic: \n    int dp[100001][2];\n    // in this i am checking for the last to front so i am \n    // finding the decreaing sequence from th
```\nclass Solution {\npublic: \n    int dp[100001][2];\n    // in this i am checking for the last to front so i am \n    // finding the decreaing sequence from the last to front\n    int findans(vector<int>&a,vector<int>&b,int i,int val)\n    {\n        if(i==0)\n            return 0;\n        if(dp[i][val]!=-1)\n            return dp[i][val];\n        int ans=INT_MAX-1;\n        // 1 denote precious values were swapped \n        // 0 denoted previous values were not swapped\n        \n        if(val==1)\n        {\n           // not swapping the current values\n            if(a[i]>b[i-1] && b[i]>a[i-1])\n            {\n                ans=min(ans,findans(a,b,i-1,0));\n            }\n            // swapping the current values\n            if(a[i]>a[i-1] && b[i]>b[i-1])\n            {\n                ans=min(ans,1+findans(a,b,i-1,1));\n            }\n        }\n        else\n        {\n           // not swapping the current values\n            if(a[i]>a[i-1] && b[i]>b[i-1])\n            {\n                ans=min(ans,findans(a,b,i-1,0));\n            }\n            // swapping the current values\n             if(a[i]>b[i-1] && b[i]>a[i-1])\n            {\n                ans=min(ans,1+findans(a,b,i-1,1));\n            }\n        }\n        // return the min ans\n        return dp[i][val]=ans;\n    }\n    int minSwap(vector<int>& a, vector<int>& b) {\n        memset(dp,-1,sizeof(dp));\n        int n=a.size();\n        // return the min of if last values were swapped or not\n        return min(findans(a,b,n-1,0),1+findans(a,b,n-1,1));\n    }\n};\n```\n\nConsider UPVOTE If you like it
['Dynamic Programming', 'Recursion', 'Memoization', 'C', 'C++']