C++ Recursive (TLE) --> Memoization
If you have any doubts : Please Contact : https://www.linkedin.com/in/shubham-dangwal-307347197/\nC++ Recursive CODE=>TLE \n\nclass Solution {\npublic:\n   \n  
If you have any doubts : Please Contact : https://www.linkedin.com/in/shubham-dangwal-307347197/\nC++ Recursive CODE=>TLE \n```\nclass Solution {\npublic:\n   \n    int helper(vector<int>& a, vector<int>& b, int i,int prevA, int prevB, bool swap)\n    {\n        if(i==a.size()) return 0;\n        int res=INT_MAX;\n        \n        // no swaps\n        if(a[i]>prevA and b[i]>prevB)\n            res=helper(a,b,i+1,a[i],b[i],0);\n        // swaps\n        if(b[i]>prevA and a[i]>prevB)\n            res=min(res,helper(a,b,i+1,b[i],a[i],1)+1);\n        return res;\n    }\n    int minSwap(vector<int>& nums1, vector<int>& nums2) {\n        return helper(nums1, nums2,0,-1,-1,0);\n    }\n};\n```\n\nC++ Memoized CODE \n\n```\nclass Solution {\npublic:\n    \n   \n    int helper(vector<int>& a, vector<int>& b, int i,int prevA, int prevB, bool swap,vector<vector<int>>&dp)\n    {\n        if(i==a.size()) return 0;\n        if(dp[i][swap]!=-1) return dp[i][swap];\n        int res=INT_MAX;\n        \n        // no swaps\n        if(a[i]>prevA and b[i]>prevB)\n            res=helper(a,b,i+1,a[i],b[i],0,dp);\n        // swaps\n        if(b[i]>prevA and a[i]>prevB)\n            res=min(res,helper(a,b,i+1,b[i],a[i],1,dp)+1);\n        return dp[i][swap]=res;\n    }\n\n    int minSwap(vector<int>& nums1, vector<int>& nums2) {\n        vector<vector<int>>dp(nums1.size()+1, vector<int>(2,-1));\n        return helper(nums1, nums2,0,-1,-1,0,dp);\n    }\n};\n```
['Recursion', 'Memoization']