C++ Easy and simple solution Recrusive->TopDown->BottomUp
Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F\n\nTh
**Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F**\n\n**There are Different method to solve This question**. \n* **Recursive (TLE)**\n* **Recursive** + **Dp** (Accepted) \n* **Bottom Up (DP)**  (Accepted) \n\n**Approach** 1: **Recursive (TLE)**\n```\nclass Solution {\npublic:\n    int solve(vector<int>& nums1, vector<int>& nums2,int index, bool swapped){\n        if(index==nums1.size()) return 0;\n        int ans=INT_MAX;\n        int prev1=nums1[index-1];\n        int prev2=nums2[index-1];\n        \n        if(swapped){\n            swap(prev1,prev2);\n        }\n        \n        if(nums1[index]>prev1 && nums2[index]>prev2)\n            ans=min(ans,solve(nums1,nums2, index+1, 0));\n        if(nums1[index]> prev2 && nums2[index]>prev1)\n            ans=min(ans,1+solve(nums1,nums2,index+1,1));\n        \n        return ans;\n    }\n    int minSwap(vector<int>& nums1, vector<int>& nums2) {\n\n        //it means that previous index were swapped or not \n            nums1.insert(nums1.begin(),-1);\n            nums2.insert(nums2.begin(),-1);\n            bool swapped=0;\n            return solve(nums1, nums2,1,swapped);\n        \n        }                                                         \n};\n```\n\n**Approach** 2 : **Recursive**+**Dp**\n\n```\nclass Solution {\npublic:\n    int solve(vector<int>& nums1, vector<int>& nums2,int index, bool swapped,vector<vector<int>>&dp){\n        if(index==nums1.size()) return 0;\n        if(dp[index][swapped]!=-1) return dp[index][swapped];\n        int ans=INT_MAX;\n        int prev1=nums1[index-1];\n        int prev2=nums2[index-1];\n        \n        if(swapped){\n            swap(prev1,prev2);\n        }\n        \n        if(nums1[index]>prev1 && nums2[index]>prev2)\n            ans=min(ans,solve(nums1,nums2, index+1, 0,dp));\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    int minSwap(vector<int>& nums1, vector<int>& nums2) {\n\n        //it means that previous index were swapped or not \n            nums1.insert(nums1.begin(),-1);\n            nums2.insert(nums2.begin(),-1);\n            bool swapped=0;\n            vector<vector<int>>dp(nums1.size()+1,vector<int>(2,-1));\n            return solve(nums1, nums2,1,swapped,dp);\n        \n        }                                                         \n};\n```\nApproach 3: **Bottom up**\n```\nclass Solution {\npublic:\n    int minSwap(vector<int>& nums1, vector<int>& nums2) {\n\n        //it means that previous index were swapped or not \n            \n            nums1.insert(nums1.begin(),-1);\n            nums2.insert(nums2.begin(),-1);\n            bool swapped=0;\n            vector<vector<int>>dp(nums1.size()+1,vector<int>(2,0));\n            \n            for(int index=nums1.size()-1;index>=1;index--){\n                for(int swapped=1;swapped>=0;swapped--){\n                    int ans=INT_MAX;\n                        int prev1=nums1[index-1];\n                        int prev2=nums2[index-1];\n\n                        if(swapped){\n                            swap(prev1,prev2);\n                        }\n\n                        if(nums1[index]>prev1 && nums2[index]>prev2)\n                            ans=min(ans,dp[index+1][0]);\n                        if(nums1[index]> prev2 && nums2[index]>prev1)\n                            ans=min(ans,1+dp[index+1][1]);\n\n                         dp[index][swapped]=ans;\n                }\n            }\n            return dp[1][1];\n        \n        }                                                         \n};\n\n```\n****Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F****
['Recursion', 'C', 'C++']