C++ || Two Pointers || Set || Greedy ✔✔
\n     const int mod = 1e9 + 7;\n \n\t class Solution {\n\t public:\n\t\t int maxSum(vector& nums1, vector& nums2) {\n    \n         set s;\n         for(int i 
\n     const int mod = 1e9 + 7;\n \n\t class Solution {\n\t public:\n\t\t int maxSum(vector<int>& nums1, vector<int>& nums2) {\n    \n         set<int> s;\n         for(int i : nums2){\n\t\t        s.insert(i);\n\t\t   }\n        \n         long long int a = 0 , b = 0 , j = 0 , m = nums1.size() , n = nums2.size() , cnt = 0;\n         for(int i=0;i<m;i++){\n             a += nums1[i]%mod;\n             if(s.count(nums1[i])){\n                 while(j < n && nums2[j] != nums1[i]){\n                      b += nums2[j++]%mod;\n                 }\n                 b += nums2[j++]%mod;\n                 cnt += max(a , b);\n                 a = 0 , b = 0;\n             }\n         }\n         \n         while(j < n){\n              b += nums2[j++] % mod;    \n         }\n         cnt += max(a , b) % mod;\n         return cnt%mod;   \n     }\n  };
['Greedy', 'C', 'Ordered Set', 'C++']