id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 0 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& n, vector<int>& m) {\n int i=0,j=0;\n while(i<n.size() && j<m.size()){\n if(n[i]==m[j]){\n return m[j];\n }\n else if(n[i]<m[j]){\n i++;\n }\n else if... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 0 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) \n {\n int n=nums1.size();\n int m=nums2.size();\n int i=0;\n int j=0;\n while(i<n && j<m)\n {\n if(nums1[i]==nums2[j])\n {\n return nums1[i... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 0 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n int idx1 = 0,idx2 = 0;\n while(idx1 < nums1.size() && idx2 < nums2.size()){\n if(nums1[idx1] == nums2[idx2])\n return nums1[idx1];\n else if(nums1[idx1] < nums2[idx2])... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 0 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n int p1 = 0, p2 = 0;\n\n if (nums1.empty() || nums2.empty())\n return -1;\n\n while (p1 < nums1.size() && p2 < nums2.size())\n {\n if (nums1[p1] > nums2[p2]) { ++p2... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 0 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n int p1 = 0, p2 = 0;\n\n while (p1 < nums1.size() && p2 < nums2.size())\n {\n if (nums1[p1] > nums2[p2]) { ++p2; }\n else if (nums1[p1] < nums2[p2]) { ++p1; }\n ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 2 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) \n {\n int n=nums1.size();\n int m=nums2.size();\n int i=0;\n int j=0;\n while(i<n && j<m)\n {\n if(nums1[i]==nums2[j])\n {\n return nums1[i... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 2 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n int p1 = 0, p2 = 0;\n\n while (p1 < nums1.size() && p2 < nums2.size())\n {\n if (nums1[p1] > nums2[p2]) { ++p2; }\n else if (nums1[p1] < nums2[p2]) { ++p1; }\n ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n sort(nums1.begin(), nums1.end());\n sort(nums2.begin(), nums2.end());\n\n int i = 0, j = 0;\n\n while (i < nums1.size() && j < nums2.size... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n std::vector<int> intersection; \n\n intersection.resize(std::min(nums1.size() , nums2.size()));\n\n auto it = std::set_intersection(nums1.begin() , nums1.end() , nums2.begin() , nums2.end() , inter... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n bool binarySearch(vector<int>& arr, int target) { // O(logn)\n int left = 0, right = arr.size() - 1;\n while (left <= right) {\n int mid = left + (right - left) / 2;\n if (arr[mid] == target) {\n return true;\n } e... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n sort(nums1.begin(), nums1.end());\n sort(nums2.begin(), nums2.end());\n\n if (nums1.size() > nums2.size()) {\n for (int target : nums2) {\n int left = ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n\n sort(nums1.begin(), nums1.end());\n sort(nums2.begin(), nums2.end());\n\n int i = 0, j = 0;\n \n while (i < nums1.size() && j < nums2.size()) {\n if (nums1[i] == nums2[j]... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n \n sort(nums1.begin(), nums1.end());\n sort(nums2.begin(), nums2.end());\n\n int i = 0, j = 0;\n\n while (i < nums1.size() && j < nums2.size()) {\n if (nums1[i] == nums2[j]) {\n ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n\tstatic int getCommon(const std::vector<int> nums1, const std::vector<int> nums2) {\n\t\tif (nums1.size() < nums2.size()) {\n\t\t\tfor (const int& num : nums1)\n\t\t\t\tif (std::binary_search(nums2.begin(), nums2.end(), num))\n\t\t\t\t\treturn num;\n\t\t}\n\t\telse {\n\t\t\tfor ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2)\n {\n vector<int>merged(nums1.size()+nums2.size());\n merge(nums1.begin(),nums1.end(),nums2.begin(),nums2.end(),merged.begin());\n for(int i=0;i<merged.size()-1;i++)\n {\n if((bina... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n for(int i=1;i<nums1.size();i++){\n if(nums1[i]==nums1[i-1]){\n nums1[i]=-3;\n }\n }\n for(int i=1;i<nums2.size();i++){\n if(nums2[i]==nums2[i-1]){\n ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n for(int i=1;i<nums1.size();i++){\n if(nums1[i]==nums1[i-1]){\n nums1[i]=-3;\n }\n }\n for(int i=1;i<nums2.size();i++){\n if(nums2[i]==nums2[i-1]){\n ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n ios_base::sync_with_stdio(false); cin.tie(NULL);\n unordered_set<int> set1(nums1.begin(), nums1.end());\n int min_common = numeric_limits<int>::max();\n bool found_common = false;\n f... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n std::unordered_set<int> hash2;\n int min_elem = -1;\n for (const auto& elem: nums2) ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n set<int> copy2(nums2.begin(), nums2.end());\n for (auto num : nums1) {\n if (num > nums2[nums2.size() -1]) return -1;\n if (copy2.find(num) != copy2.end()) return num;\n }\n ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n set<int> s;\n\n for (int i = 0; i < nums1.size(); ++i) {\n s.insert(nums1[i]);\n }\n\n int ans = -1;\n\n for (int i = 0; i < nums2.size(); ++i) {\n if (s.find(nu... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n unordered_set<int>st(nums1.begin(),nums1.end());\n\n for(auto&ch:nums2){\n if(st.find(ch)!=st.end()){\n return ch;\n }\n }\n return -1;\n }\n};",
"m... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n unordered_set<int> st(nums1.begin(),nums1.end());\n for(int &num:nums2)\n {\n if(st.find(num)!=st.end())\n return num;\n }\n return -1;\n }\n};",
"memor... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n unordered_set<int> st(nums1.begin(), nums1.end());\n for (const auto& num : nums2) if (st.find(num) != st.end()) return num;\n return -1;\n }\n};",
"memory": "69500"
} |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n unordered_set<int> st;\n for(int i:nums1)st.insert(i);\n for(int i:nums2){\n if(st.count(i)==1){\n return i;\n }\n }\n return -1;\n }\n};",
"... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n unordered_set<int>st(begin(nums1),end(nums1));\n for(int &num:nums2){\n if(st.find(num)!=st.end()){\n return num;\n }\n }\n return -1;\n }\n};",
"me... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n map<int,int> m;\n for(int i=0;i<nums1.size();i++){\n m[nums1[i]]=1;\n }\n int res=INT_MAX;\n for(int i=0;i<nums2.size();i++){\n if(m.find(nums2[i])!=m.end()){\n ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n map<int,int> m;\n int mini=INT_MAX;\n bool f=0;\n for(int i=0; i<nums1.size(); i++)\n {\n m[nums1[i]]++;\n }\n for(int i=0; i<nums2.size(); i++)\n {\n ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n map<int,int> t;\n for(int i=0;i<nums1.size();i++){\n t[nums1[i]]++;\n }\n for(int i=0;i<nums2.size();i++){\n if(t.find(nums2[i])!=t.end()){\n return nums... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n map<int,int>mp;\n for(int i=0;i<nums1.size();i++){\n mp[nums1[i]]++;\n } \n for(int i=0;i<nums2.size();i++){\n if(mp.find(nums2[i])!=mp.end()){\n return nums2[i];\n }\n ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n map<int,int> mp;\n vector<int> ans;\n\n for(auto it : nums1)\n mp[it]++;\n\n \n for(auto it : nums2){\n if(mp.find(it) != mp.end()){\n ans.push_back(... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "#include <bits/stdc++.h>\nclass Solution {\npublic:\n int max(int i, int n) {\n if(i<n) return n;\n return i;\n }\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n unordered_set<int> track1;\n unordered_set<int> track2;\n\n int max1 = nums1.size();\n ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n set<int> n1;\n set<int> n2;\n auto iter1 = nums1.begin();\n auto iter2 = nums2.begin();\n while(iter1 != nums1.end() || iter2 != nums2.end()) {\n if(iter1 != nums1.end()) {... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n vector<int> dupli(vector<int>& arr) {\n // Sort the array\n sort(arr.begin(), arr.end());\n\n // Use std::unique to move duplicates to the end\n auto lastUnique = unique(arr.begin(), arr.end());\n\n // Resize the vector to remove the duplicates\n ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) \n {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n unordered_map<int,int> mp;\n for(int i=0;i<nums1.size();i++)\n {\n mp[nums1[i]]=1;\n ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<int, int> mp;\n for (int num : nums1) {\n mp[num]++;\n }\n for (int num : nums2) {\n if (mp[num] > 0) {\n return num;\n }\n ... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n\n\tunordered_map<int, bool> table;\n\n\tfor (int i : nums1)\n\t\ttable[i] = true;\n\tfor (int j : nums2)\n\t\tif (table[j] == true)\n\t\t\treturn j;\n\treturn -1;\n}\n};",
"memory": "77300"
} |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<int, int> mp;\n for (int num : nums1)\n mp[num]++;\n for (int num : nums2)\n if (mp[num] > 0)\n return num;\n return -1;\n }\n};",
"me... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<int, int> mp;\n for (int num : nums1)\n mp[num]++;\n for (int num : nums2)\n if (mp[num] > 0)\n return num;\n return -1;\n }\n};",
"me... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n unordered_set<int>n1,n2;\n for(int i:nums1)\n {\n n1.insert(i);\n }\n for(int j:nums2)\n {\n n2.insert(j);\n if(n1.count(j))\n return j;\n }\n r... |
2,634 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in non-decreasing order, return <em>the <strong>minimum integer common</strong> to both arrays</em>. If there is no common integer amongst <code>nums1</code> and <code>nums2</code>, return <code>-1</code>.</p>
<p>Note that an integer is said... | 3 | {
"code": "class Solution {\npublic:\n int getCommon(vector<int>& nums1, vector<int>& nums2) {\n map<int, int> occur;\n for (int num: nums1){\n if (occur[num] < 1){\n occur[num]++;\n }\n }\n for (int num: nums2){\n if (occur[num] == 1){\n ... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\n\nclass Solution {\npublic:\n long long maxScor... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "#pragma GCC optimize(\"Ofast,no-stack-protector\")\n#pragma GCC optimize(\"no-math-errno,unroll-loops\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4\")\n\nstatic int speedup = []() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nclass Solut... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int indices[nums2.size()];\n\n for( int i = 0 ; i < nums2.size() ; ++i ) indices[i] = i;\n std::sort( indices , indices + nums2.size() , [&nums2](int l , int r){ return nums2[r] ... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n=nums1.size();\n pair<int,int>pr[n];\n for(int i=0;i<n;i++)pr[i]={nums2[i],nums1[i]};\n sort(pr,pr+n);\n long long sum=0,ans=0,sz=0;\n priority_queue<int>pq;\n... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n [[nodiscard]]\n auto maxScore(const std::vector<int>& nums1, const std::vector<int>& nums2, const int k) const\n -> long long\n {\n const std::size_t n { nums1.size() };\n\n long long max { 0 };\n \n if (k == 1)\n {\n for... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "#pragma GCC optimize(\"Ofast,no-stack-protector\")\n#pragma GCC optimize(\"no-math-errno,unroll-loops\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4\")\n\nstatic int speedup = []() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nclass Solut... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n ios_base::sync_with_stdio(false);\n vector<int> index(nums2.size(),0);\n for (int i=0; i< nums2.size();i++){\n index[i]= i;\n }\n sort(index.begin(),index.end()... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums1.size();\n if (k == n)\n {\n long long ans = 0;\n for (int num1 : nums1)\n {\n ans += num1;\n }\n int ... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums1.size();\n if (k == n)\n {\n long long ans = 0;\n for (int num1 : nums1)\n {\n ans += num1;\n }\n int ... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<int> indices(nums2.size());\n iota(indices.begin(), indices.end(), 0);\n sort(indices.begin(), indices.end(), [&](int a, int b) {\n return nums2[a] > nums2[b];\n ... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums1.size();\n vector<int> indices(n);\n for (int i = 0; i < n; ++i) {\n indices[i] = i;\n }\n sort(indices.begin(), indices.end(), [&](int i, int j) {... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums1.size();\n vector<int> indices(n);\n for (int i = 0; i < n; ++i) {\n indices[i] = i;\n }\n sort(indices.begin(), indices.end(), [&](int i, int j) ... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n void sort_w_folower(int *toSort, int *toFollow, int first, int last) {\n int l{first}, r{last}, m{(l + r) / 2}, pivot{0}, temp{0};\n // best way to choose pivot is to choose middle between left, middle and right.\n auto &left = toSort[l];\n auto &m... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n void sort_w_folower(int *toSort, int *toFollow, int first, int last) {\n int l{first}, r{last}, m{(l + r) / 2}, pivot{0}, temp{0};\n // best way to choose pivot is to choose middle between left, middle and right.\n auto &left = toSort[l];\n auto &m... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n \n int n = nums1.size();\n vector<pair<int,int>> v(n);\n for (int i=0;i<n;++i) {\n v[i] = {nums2[i], nums1[i]};\n }\n \n sort(v.begin(),v.end());\... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums1.size();\n\n vector<pair<int, int>> vec(n);\n\n for (int i = 0; i < n; i++) {\n vec[i] = {nums1[i], nums2[i]};\n }\n\n auto lambda = [&](auto& P1, ... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums1.size();\n \n vector<pair<int,int>> vec(n);\n \n for(int i = 0; i<n; i++) {\n vec[i] = {nums1[i], nums2[i]};\n }\n \n auto lam... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "#pragma GCC optimize(\"Ofast,no-stack-protector\")\n#pragma GCC optimize(\"no-math-errno,unroll-loops\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4\")\nclass Solution {\npublic:\n long long maxScore(vector<int>& s_n1, vector<int>& s_n2, int k) {\n ios_base::sync_with_stdio(false);cin.tie(null... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n int N;\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n\n N = nums1.size();\n vector<int> index;\n for (int i = 0; i < N; ++i) index.push_back(i);\n sort(index.begin(), index.end(), [&nums2] (int x, int y) {return nums2[x]... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums1.size();\n vector<int> idx;\n for (int i = 0; i < n; ++i)\n idx.push_back(i);\n auto comp = [&](int v1, int v2) {\n return nums2[v1] > nums2[v2];\n };\n sort(idx.begin... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& n1, vector<int>& n2, int k) {\n long long res = 0, sum = 0;\n vector<int> id(n1.size());\n iota(begin(id), end(id), 0);\n sort(begin(id), end(id), [&](int i, int j){ return n1[i] > n1[j]; });\n priority_queue<pair<int,int>, v... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n\n if(k==1)\n {\n long long res = 0;\n for(unsigned i=0; i<nums2.size();i++)\n res = std::max(static_cast<long long>(nums1[i]*nums2[i]), res);\n ... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n\n struct Compare {\n const std::vector<int>& B;\n Compare(const std::vector<int>& B) : B(B) {}\n bool operator()(int i, int j) const { return B[i] < B[j]; }\n }; \n long long maxScore(vector<int>& A, vector<int>& B, int k) {\n std::vecto... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<pair<int,int>> sorted;\n sorted.reserve(nums1.size());\n for (int i = 0; i < nums1.size(); i++)\n sorted.emplace_back(nums1[i], nums2[i]);\n sort(sorted.begin()... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<pair<int,int>> sorted;\n sorted.reserve(nums1.size());\n for (int i = 0; i < nums1.size(); i++)\n sorted.emplace_back(nums1[i], nums2[i]);\n sort(sorted.begin()... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<pair<int,int>> sorted;\n sorted.reserve(nums1.size());\n for (int i = 0; i < nums1.size(); i++)\n sorted.emplace_back(nums1[i], nums2[i]);\n sort(sorted.begin()... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<pair<int, int>> sorted;\n sorted.reserve(nums1.size());\n\n for(int i=0; i<nums1.size(); ++i)\n {\n sorted.emplace_back(nums2[i], nums1[i]);... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "#include <vector>\n#include <queue>\n#include <algorithm>\n\nusing namespace std;\n\nclass Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n // Step 1: Create pairs of (nums2[i], nums1[i])\n int n = nums1.size();\n vector<pair<int, int>> pai... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums1.size();\n\n // 将索引按照 nums2 从大到小排序\n vector<pair<int, int>> pairs(n);\n for (int i = 0; i < n; ++i) {\n pairs[i] = { nums2[i], nums1[i] };\n }\n ... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 0 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums1.size();\n vector<pair<int,int>> vec(n);\n for (int i = 0; i < n; i++) {\n vec[i] = {nums2[i], nums1[i]};\n }\n sort(rbegin(vec), rend(vec));\n ... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 1 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums1.size();\n priority_queue<pair<int,int>> nums2_max;\n // lets push all the elements of nums2 along with idxs into priority queue to get largest elements of nums2\n f... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 1 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n // (nums2, nums1)\n vector<pair<int, int>> pairs;\n for (int i = 0; i < nums1.size(); i++) {\n auto temp = pair<int, int>(-nums2[i], -nums1[i]);\n pairs.pu... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 1 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<pair<int,int>> arr;\n for(int i=0;i<nums1.size();i++){\n arr.push_back({nums2[i],nums1[i]});\n }\n sort(arr.begin(),arr.end(),greater<pair<int,int>>());\n ... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 1 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n long long ans = 0;\n vector<pair<int,int>> vec;\n for(int i=0; i<nums1.size(); i++){\n vec.push_back({nums1[i], nums2[i]});\n }\n\n sort(vec.begin(), vec.end(),... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 2 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums2.size();\n vector<int> index(n);\n iota(index.begin(), index.end(), 0);\n \n // get the index sorted according nums2\n sort(index.begin(), index.end(),... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 2 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums2.size();\n vector<int> index(n);\n iota(index.begin(), index.end(), 0);\n \n // get the index sorted according nums2\n sort(index.begin(), index.end(),... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 2 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums2.size();\n vector<int> index(n);\n iota(index.begin(), index.end(), 0);\n \n // get the index sorted according nums2\n sort(index.begin(), index.end(),... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 2 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums2.size();\n vector<int> index(n);\n iota(index.begin(), index.end(), 0);\n \n // get the index sorted according nums2\n sort(index.begin(), index.end(),... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 2 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n\n const int nums_len = nums1.size();\n if (nums_len<k) return -1;\n\n vector<tuple<int,int>> nums;\n for (int i=0; i<nums_len; ++i) {\n nums.emplace_back(nums1[i], num... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 2 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n \n int n=nums1.size();\n vector<pair<int,int>> arr(n);\n for(int i=0;i<n;i++)\n {\n arr.push_back({nums2[i],nums1[i]});\n }\n \n sort(arr.... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums1.size();\n vector<pair<int,int>> pairs(n);\n\n for(int i=0; i<n; ++i){\n pairs.push_back({nums2[i],nums1[i]});\n }\n\n sort(pairs.rbegin(),pairs.re... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums1.size();\n vector<pair<int,int>> pairs(n);\n\n for(int i =0; i < n;i++)\n {\n pairs.push_back({nums2[i],nums1[i]});\n }\n sort(pairs.rbegin... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums1.size();\n vector<pair<int, int>>pairs(n);\n for(int i=0; i<n; i++){\n pairs.push_back({nums2[i], nums1[i]});\n }\n sort(pairs.rbegin(), pairs.rend... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "class Solution {\npublic:\n void countsort(vector<int>&v1, vector<int>&v2, vector<long long>&temp1, vector<long long>&temp2){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n \n int n = v1.size();\n int mn = *min_element(v1.begin(),... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "class Solution {\npublic:\n void countsort(vector<int>&v1, vector<int>&v2, vector<long long>&temp1, vector<long long>&temp2){\n int n = v1.size();\n int mn = *min_element(v1.begin(), v1.end());\n int mx = *max_element(v1.begin(), v1.end());\n vector<int> count(mx+1,0);\n ... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "#define ll long long\nclass Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums1.size();\n vector<pair<int, int>> vp;\n for (int i = 0; i < n; i++) {\n vp.push_back({nums1[i], nums2[i]});\n }\n sort(vp.rbe... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<pair<int,int>>v;\n for(int i = 0; i < nums2.size(); i++) v.push_back({nums2[i],i});\n sort(v.begin(),v.end());\n int n = nums1.size();\n vector<long long>rmax(n, 0)... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "class Solution {\npublic:\nlong long solve(priority_queue<int> pq,int k)\n{\n long long sum=0;\n while(!pq.empty()&&k)\n {\n sum+=pq.top();\n pq.pop();\n k--;\n }\n return sum;\n}\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<pa... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "typedef long long int ll;\nbool comp(pair<ll,ll>&p1,pair<ll,ll>&p2){\n if(p1.second>p2.second){\n return true;\n }\n return false;\n}\nclass Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<pair<ll,ll>> v;\n int n=nums1.size... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n\tint n = nums1.size();\n\tvector<pair<long long,long long>> numsCombined;\n\tfor(int i=0;i<n;i++) {\n\t\tnumsCombined.push_back({nums2[i],nums1[i]});\n\t}\n\tsort(numsCombined.begin(),numsCombined.end());\n... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "class Solution {\npublic:\n // static bool comparator(pair<int,int> &a,pair<int,int> &b)\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<pair<long long,long long >> v;\n int n = nums1.size();\n for(int i=0;i<n;++i){\n v.push_back({nums2[i... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "class Solution {\npublic:\nstatic bool cmp(pair<long long,long long> &a,pair<long long,long long>&b){\n return a.second>b.second;\n}\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<pair<long long,long long>> v;\n for(long long i=0;i<nums1.size();i++){\n ... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "class Solution {\npublic:\n using ll = long long;\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<pair<ll,ll>> vp;\n for(int i=0;i<nums1.size();i++){\n vp.push_back({nums1[i],nums2[i]});\n }\n sort(vp.begin(), vp.end(), [](const pa... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<pair<long long, long long>> vec;\n for(long long i=0;i<nums1.size();i++){\n vec.push_back(make_pair(nums2[i], nums1[i]));\n }\n\n sort(vec.begin(), vec.end());\... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "class Solution {\npublic:\n long long dpa[100005], dpb[100005];\n struct Node{\n long long a,b;\n Node(long long c, long long d):a(c), b(d){}\n bool operator <(const Node&c) const{\n return b>c.b;\n }\n };\n long long maxScore(vector<int>& nums1, vector<in... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<pair<int, int>> v;\n int sz = nums1.size();\n for(int i = 0; i < sz; ++i)\n v.push_back({nums2[i], nums1[i]});\n sort(v.rbegin(), v.rend());\n set<pair<i... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<pair<long long int,long long int>> a;\n for(long long int i=0; i<nums1.size(); i++){\n a.push_back({nums2[i], nums1[i]});\n }\n sort(a.rbegin(), a.rend());\n ... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "class Solution {\npublic:\n\n struct NumsBundle {\n int num1 = 0;\n int num2 = 0;\n };\n\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n // Given a number in num2, among all the numbers greater than it, find the k greatest numbers in nums1.\n\n /... |
2,636 | <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of equal length <code>n</code> and a positive integer <code>k</code>. You must choose a <strong>subsequence</strong> of indices from <code>nums1</code> of length <code>k</code>.</p>
<p>For chosen indices <code>i<su... | 3 | {
"code": "class Solution {\npublic:\n long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {\n // first make get the sequence with k highest values of nums2\n // then replace each element of this sequence, based on which element is giving the minimum additino from num1\n priority... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.