id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,235 | <p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ... | 3 | {
"code": "class Solution {\npublic:\n typedef pair<int,char> pic;\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n long long ans = 0;\n map<char, vector<char>> adj;\n map<pair<char, char>, int> dist;\n map<pa... |
3,235 | <p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ... | 3 | {
"code": "class Djikstra{\n public:\n vector<vector<pair<int, int>>> children;\n Djikstra(vector<char> origin, vector<char> destination, vector<int> cost): children(26, vector<pair<int, int>>()){\n for (int i = 0; i < origin.size(); i++){\n children[origin[i] - 97].push_bac... |
3,235 | <p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ... | 3 | {
"code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original,\n vector<char>& changed, vector<int>& cost) {\n\n vector<pair<int, int>> adj[26];\n\n int n = original.size();\n for (int i = 0; i < n; i++) {\n ... |
3,235 | <p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ... | 3 | {
"code": "class Solution {\npublic:\n long long bfs(int s,int d,vector<pair<int,int>> adj[]){\n vector<int> dist(26,(int)1e9);\n dist[s] = 0;\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;\n pq.push({0,s});\n\n while(!pq.empty()){\n a... |
3,235 | <p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ... | 3 | {
"code": "class Solution {\npublic:\n long long bfs(int s,int d,vector<pair<int,int>> adj[]){\n vector<int> dist(26,(int)1e9);\n dist[s] = 0;\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;\n pq.push({0,s});\n\n while(!pq.empty()){\n a... |
3,235 | <p>You are given two <strong>0-indexed</strong> strings <code>source</code> and <code>target</code>, both of length <code>n</code> and consisting of <strong>lowercase</strong> English letters. You are also given two <strong>0-indexed</strong> character arrays <code>original</code> and <code>changed</code>, and an integ... | 3 | {
"code": "class Solution {\npublic:\n long long minimumCost(string source, string target, vector<char>& original, vector<char>& changed, vector<int>& cost) {\n const int n = cost.size();\n vector<pair<int, char>> g[26];\n for (int i = 0;i < n; ++i) {\n char u = original[i], v = cha... |
371 | <p>Given two integers <code>a</code> and <code>b</code>, return <em>the sum of the two integers without using the operators</em> <code>+</code> <em>and</em> <code>-</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> a = 1, b = 2
<strong>Output:</strong> 3
</pre><p... | 0 | {
"code": "class Solution {\npublic:\n int getSum(int a, int b) {\n while (b != 0) {\n unsigned carry = (a & b); // Calculate carry\n a = a ^ b; // Sum without carry\n b = carry << 1; // Move carry to the next higher bit\n }\n return a;... |
371 | <p>Given two integers <code>a</code> and <code>b</code>, return <em>the sum of the two integers without using the operators</em> <code>+</code> <em>and</em> <code>-</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> a = 1, b = 2
<strong>Output:</strong> 3
</pre><p... | 0 | {
"code": "class Solution {\npublic:\n int getSum(int a, int b) {\n\n long mask = 0xFFFFFFFF;\n\n while(b!=0) {\n int answer = (a ^ b) & mask;\n int carry = (((a&b) &mask) << 1);\n\n a = answer;\n b = carry;\n }\n\n return a < INT_MAX ? a : ~(... |
371 | <p>Given two integers <code>a</code> and <code>b</code>, return <em>the sum of the two integers without using the operators</em> <code>+</code> <em>and</em> <code>-</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> a = 1, b = 2
<strong>Output:</strong> 3
</pre><p... | 0 | {
"code": "class Solution {\npublic:\n int getSum(int a, int b) {\n uint32_t carry = a&b;\n int sumWithoutCarry = a^b;\n int actualCarry = carry<<1;\n while(carry != 0){\n carry = sumWithoutCarry & actualCarry;\n sumWithoutCarry = actualCarry ^ sumWithoutCarry;\n ... |
371 | <p>Given two integers <code>a</code> and <code>b</code>, return <em>the sum of the two integers without using the operators</em> <code>+</code> <em>and</em> <code>-</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> a = 1, b = 2
<strong>Output:</strong> 3
</pre><p... | 0 | {
"code": "class Solution {\npublic:\n int getSum(int a, int b) {\n int res = a ^ b;\n int carry = (a & b) << 1;\n \n while (carry) {\n int temp = (res & carry) << 1;\n res = res ^ carry;\n carry = temp;\n }\n\n return res;\n }\n};",
"... |
371 | <p>Given two integers <code>a</code> and <code>b</code>, return <em>the sum of the two integers without using the operators</em> <code>+</code> <em>and</em> <code>-</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> a = 1, b = 2
<strong>Output:</strong> 3
</pre><p... | 0 | {
"code": "class Solution {\npublic:\n int getSum(int a, int b) {\n int c=a+b;\n return c;\n }\n};",
"memory": "7200"
} |
371 | <p>Given two integers <code>a</code> and <code>b</code>, return <em>the sum of the two integers without using the operators</em> <code>+</code> <em>and</em> <code>-</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> a = 1, b = 2
<strong>Output:</strong> 3
</pre><p... | 0 | {
"code": "class Solution {\npublic:\n int getSum(int a, int b) {\n return a+b;\n \n }\n};",
"memory": "7200"
} |
371 | <p>Given two integers <code>a</code> and <code>b</code>, return <em>the sum of the two integers without using the operators</em> <code>+</code> <em>and</em> <code>-</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> a = 1, b = 2
<strong>Output:</strong> 3
</pre><p... | 0 | {
"code": "class Solution {\npublic:\n int getSum(int a, int b) {\n return a+b;\n }\n};",
"memory": "7300"
} |
371 | <p>Given two integers <code>a</code> and <code>b</code>, return <em>the sum of the two integers without using the operators</em> <code>+</code> <em>and</em> <code>-</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> a = 1, b = 2
<strong>Output:</strong> 3
</pre><p... | 0 | {
"code": "class Solution {\npublic:\n int getSum(int a, int b) {\n while (b!=0){\n int t = (a & b) << 1;\n a = a ^ b;\n b = t;\n }\n return a;\n }\n};",
"memory": "7300"
} |
371 | <p>Given two integers <code>a</code> and <code>b</code>, return <em>the sum of the two integers without using the operators</em> <code>+</code> <em>and</em> <code>-</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> a = 1, b = 2
<strong>Output:</strong> 3
</pre><p... | 0 | {
"code": "class Solution {\npublic:\n int getSum(int a, int b) {\n while(b!=0) {\n int temp=(a&b)<<1; //carry\n a=a^b; //sum\n b=temp; //carry shift left\n }\n return a;\n }\n};",
"memory": "7400"
} |
371 | <p>Given two integers <code>a</code> and <code>b</code>, return <em>the sum of the two integers without using the operators</em> <code>+</code> <em>and</em> <code>-</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> a = 1, b = 2
<strong>Output:</strong> 3
</pre><p... | 0 | {
"code": "class Solution {\npublic:\n int getSum(int a, int b) {\n int c=0;\n while(b!=0)\n {\n c=a&b;\n a=a^b;\n b=c<<1;\n }\n return a;\n }\n};",
"memory": "7400"
} |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<vector<int>> output;\n output.reserve(k);\n \n size_t nums1Size = nums1.size();\n size_t nums2Size = nums2.size();\n\n const int N = nums1Siz... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<vector<int>> output;\n output.reserve(k);\n \n size_t nums1Size = nums1.size();\n size_t nums2Size = nums2.size();\n\n const int N = nums1Siz... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\n struct Item {\n int ss{std::numeric_limits<int>::max()};\n\n std::uint16_t i{0};\n std::uint16_t j{0};\n\n constexpr auto operator<=>(const Item& other) const {\n return other.ss <=> ss;\n }\n };\n\npublic:\n std::vector<std::vector<... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n /*\n PQ size k solution. Insert all pairs into PQ while keeping it at most size k O(n^2 logk)\n */\n priority_queue< pair<int, pair<int, int>>,\n v... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n typedef std::pair<int, int> IndicesPair;\n auto comparePairs = [&](const IndicesPair& p1, const IndicesPair& p2)\n {\n return (nums1[p1.first] + nums2[p1.seco... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "\nclass Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int> &nums1, vector<int> &nums2, int k) {\n\n vector<vector<int>> ans(k, vector<int>(2, 0));\n\n auto customComprator = [&nums1, &nums2](pair<int, int> &a, pair<int, int> &b) {\n return (nums1[a.first] + num... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n typedef std::pair<int, int> IndicesPair;\n auto comparePairs = [&](const IndicesPair& p1, const IndicesPair& p2)\n {\n return (nums1[p1.first] + nums2[p1.seco... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n\n vector<vector<int>> res(k);\n priority_queue<array<int, 2>> pq;\n\n int sum = 0, maxi... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n\n vector<vector<int>> res(k);\n priority_queue<array<int, 2>> pq;\n\n int sum = 0, maxi... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution { \npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) \n {\n long left = INT_MIN, right = INT_MAX;\n while (left < right)\n {\n long mid = left+(right-left)/2;\n long count = countSmallerOrEqual(mid... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution { \npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) \n {\n long left = INT_MIN, right = INT_MAX;\n while (left < right)\n {\n long mid = left+(right-left)/2;\n long count = countSmallerOrEqual(mid... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\npublic:\n bool check(long long x,vector<int>& nums1, vector<int>& nums2, int k){\n long long c=0;\n int j=nums2.size()-1;\n for(auto&i:nums1){\n while(j>=0){\n long long val=i+nums2[j];\n if(val>x) j--;\n else... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<vector<int>>ans(k);\n priority_queue<pair<int,pair<int,int>>>pq;\n\n for(int i=0;i<nums1.size();i++){\n for(int j=0;j<nums2.size();j++){\n ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2,\n int k) {\n long long s = -2 * 1e9, e = 2 * 1e9, ans = 0;\n int n = nums1.size(), m = nums2.size();\n vector<vector<int>> v;\n while (... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "typedef tuple<int, int, int> tp;\nclass Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n if(nums1.empty() || nums2.empty()) return {};\n priority_queue<tp, vector<tp>, greater<tp>> pq;\n pq.push({nums1[0] + nums2[0], 0 , 0})... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n sort(nums1.begin(), nums1.end());\n sort(nums2.begin(), nums2.end());\n priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pa... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n sort(nums1.begin(), nums1.end());\n sort(nums2.begin(), nums2.end());\n priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pa... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "#pragma GCC optimize (\"Ofast\")\n#pragma GCC target (\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx\")\n#pragma GCC optimize (\"-ffloat-store\")\n#pragma GCC optimize (\"O3\", \"unroll-loops\")\n#pragma GCC target(\"avx,mmx,sse2,sse3,sse4\")\nauto _=[]()noexcept{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);r... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums1.size();\n\n auto comp = [&](pair<int, int>& a, pair<int, int>& b) {\n return nums1[a.first] + nums2[a.second] > nums1[b.first] + nums2[b.second];\n ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\n\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1,vector<int>& nums2, int k) {\n struct Node {\n int u,v,sum;\n bool operator<(const Node &other) const{\n return sum > other.sum;\n }\n };\n priority_queue<Node> pq;\n\n ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n int listLength = nums1.size();\n\n priority_queue<pair<int, pair<int, int>>,\n vector<pair<int, pair<int, int>>>, \n greater<pair<int, pa... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Compare {\n public:\n bool operator()(std::pair<int, int>& lhs, std::pair<int, int>& rhs){\n return (lhs.first + lhs.second) < (rhs.first + rhs.second);\n }\n};\n\nclass Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Compare {\n public:\n bool operator()(std::pair<int, int>& lhs, std::pair<int, int>& rhs){\n return (lhs.first + lhs.second) < (rhs.first + rhs.second);\n }\n};\n\nclass Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n priority_queue<pair<int, pair<int,int>>> pq;\n\n for(int i = 0; i < nums1.size(); i++){\n for(int j = 0; j < nums2.size(); j++) {\n int sum = nums1[i]... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n priority_queue<pair<int, pair<int, int>>> maxHeap;\n for(auto i:nums1)\n {\n for(auto j:nums2)\n {\n \n if(maxHeap.si... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<vector<int>> res;\n if (nums1.empty() || nums2.empty() || k <= 0)\n return res;\n int m = nums1.size();\n int n = nums2.size();\n auto co... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 1 | {
"code": "class Solution {\nprivate:\n struct Hash {\n hash<long long> _hash;\n\n size_t operator()(const pair<int,int>& key) const {\n return _hash(*((long long*) &key));\n }\n };\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n const auto compare ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n priority_queue<pair<long long ,pair<int,int>>>pq;\n for(auto &n1:nums1) {\n for(auto &n2:nums2) {\n if(pq.size()<k) {\n pq.push({n1... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n priority_queue< pair<long, pair<int,int> >, vector<pair<long,pair<int,int>>> > pq;\n\n for(int i = 0; i < nums1.size(); i++){\n for(int j = 0; j < nums2.size(); j++)... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> smallestSumsQueue;\n vector<vector<int>> smallestSumsArray;\n int indexOfNums2 = 0;\n\n ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;\n for(int n:nums1){\n pq.push({n+nums2[0],0});\n }\n vector<vector<int>>... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) \n {\n vector<vector<int>> ret;\n priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>> pq;\n for(int i=0, j = k;i<nums... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<vector<int>> fina;\n auto comparator = [](const std::pair<int,vector<int>>& a, const std::pair<int,vector<int>>& b) {\n return a.first > b.first; \n };\n ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n priority_queue<pair<int,pair<int,int>>>pq;\n int m = nums1.size();\n int n = nums2.size();\n fo... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n //brute force\n int n = nums1.size();\n int m = nums2.size();\n priority_queue<pair<int, pair<int, int>>> pq;\n for(int i = 0; i < n; i++)\n {\n ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 2 | {
"code": "class Solution {\npublic:\n struct sij {\n int sum, i, j;\n sij(int sum=0, int i=0, int j=0): sum(sum), i(i), j(j) {}\n bool operator < (const sij& b) const {\n if (this->sum != b.sum) return this->sum < b.sum;\n else if (this->i != b.i) return this->i < b.i;\n... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 2 | {
"code": "char c = [](){ios::sync_with_stdio(false); cin.tie(NULL); return 'c';}();\n\nclass Solution {\npublic:\n struct ComparePriority {\n bool operator()(const pair<int, vector<int>>& a, const pair<int, vector<int>>& b) {\n return a.first > b.first; // Min-heap\n }\n };\n\n vec... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 2 | {
"code": "class Solution {\npublic:\n typedef pair<int,pair<int,int>> P;\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<vector<int>> ans;\n priority_queue<P,vector<P>,greater<P>> pq;\n pq.push({nums1[0]+nums2[0],{0,0}});\n int n = nums... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 2 | {
"code": "class Solution {\npublic:\n struct compare {\n bool operator()(vector<int>& a, vector<int>& b) {\n return a[2] > b[2];\n }\n };\n\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n int i = 0, j = 0;\n // min heap\n ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<vector<int>> ans;\n priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;\n q.push({nums1[0] + nums2[0], 0, 0});\n unordered_map<int, u... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n set<pair<int,int>> visited; \n vector<vector<int>> ans;\n map<int, vector<pair<int,int>>> mp;\n visited.insert({0,0});\n int a = nums1[0];\n int b =... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums1.size();\n priority_queue<pair<int, pair<int, int>>,\n vector<pair<int, pair<int, int>>>,\n greater<pair<int, pair<int,... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n int n1 = nums1.size();\n int n2 = nums2.size();\n\n priority_queue< pair<int,pair<int,int>> , vector< pair<int,pair<int,int>> > , greater < pair<int,pair<int,int>> > > p... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n struct cm1 {\n bool operator()(const vector<int>& a, vector<int>& b) {\n return a[0] + a[1] > b[0] + b[1];\n }\n }; vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2,\n int k) {\n ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> minHeap; // min-heap to store pairs and their sums\n vector<vector<int>> result; // vector to store the r... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<vector<int>> smallest_pairs;\n set<pair<int, pair<int, int>>> sums;\n\n set<pair<int, int>> visited;\n\n int n1 = nums1.size(), n2 = nums2.size();\n\n ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n\n priority_queue<vector<int>> pq;\n vector<vector<int>> result(k);\n for(int ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<vector<int>> ans = {vector<int>{nums1[0], nums2[0]}};\n unordered_map<int, unordered_set<int>> visited;\n priority_queue<vector<int>> minHeap;\n int m = nu... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n #define pa pair<int,pair<int,int>>\n struct comp\n {\n bool operator()(pa &x,pa &y)\n {\n if((x.first) >(y.first))\n {\n return true;\n }\n return false;\n }\n };\n vector<vector<int>>... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "struct Compare {\n bool operator()(vector<int>& t1, vector<int>& t2) { return t1[2] > t2[2]; }\n};\nclass Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2,\n int k) {\n priority_queue<vector<int>, vector<vecto... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "#include <vector> // For vector usage\n#include <queue> // For priority_queue usage\n#include <map> // For map usage\nusing namespace std;\n\nclass Solution { // Define a Solution class\npublic:\n // Define the function that takes two vectors and an integer k\n vector<vector<int>> kSmall... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n priority_queue<vector<int>, \n vector<vector<int>>, \n greater<vector<int>>> pq;\n pq.push({nums1[0] + nums2[0], 0, 0});\n\n vector<vector<int>> result;\n ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n vector <vector <int>> res;\n set <pair <int, int>> seen;\n int n = nums1.size(), m = nums2.size();\n int i = 0, j = 0;\n priority_queue <vector <int>, vect... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n int count = 0;\n priority_queue<pair<int, vector<int>>> maxHeap;\n for(int i=0; i<nums1.size(); i++){\n // if(!maxHeap.empty() and count >= k and nums1[i] > ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "using pii = pair<int, int*>;\n\nclass Comp {\npublic:\n bool operator() (pii lhs, pii rhs) {\n return lhs.first + *lhs.second > rhs.first + *rhs.second;\n }\n};\n\nstatic int x = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(NULL);\n std::cout.tie(0);\n return 0;\n}();\... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n struct NumPair{\n int num1;\n int num2;\n size_t num2Index;\n bool operator > (const NumPair& other) const {\n return (num1 + num2) > (other.num1 + other.num2);\n }\n };\n vector<vector<int>> kSmallestPairs(vector<int>& nums... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "#include <iostream>\n#include <vector>\n#include <queue>\n#include <functional>\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n vector<vector<int>> resV; // Result vector to store the pairs\n prior... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "auto init = []() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 'c';\n}();\n\nclass Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& n1, vector<int>& n2, int k) {\n int n=n1.size();\n int m=n2.size();\n int i=0; in... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) \n {\n priority_queue<vector<int>>q;\n\n int n=nums1.size(),m=nums2.size();\n\n for(int i=0;i<n;i++)\n {\n for(int j=0;j<m;j++)\n {\n ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n set<pair<int,pair<int,int>>>st;\n st.insert({nums1[0]+nums2[0],{0,0}});\n vector<vector<int>>ans;\n map<pair<int,int>,int>mp;\n int s1=nums1.size();\n ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n set<pair<int,pair<int,int>>>st;\n st.insert({nums1[0]+nums2[0],{0,0}});\n vector<vector<int>>ans;\n map<pair<int,int>,int>mp;\n int s1=nums1.size();\n ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n \n priority_queue<pair<int,vector<int>>, vector<pair<int,vector<int>>>, greater<pair<int,vector<int>>>> pq;\n\n vector<vector<int>> res;\n set<pair<int,int>> visited... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n // Two pointer approach\n // 1, 7\n // 2, 4\n int l = 0, r = 0;\n vector<vector<int>> ans;\n priority_queue<pair<int, vector<int>>, \n ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "// default는 max heap\n// for loop 2개를 안 쓰고 BFS로 풀자\nclass Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> pq; // default: max heap, 이 문제는 min heap\n unordered_... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2,\n int k) {\n priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>>\n pq;\n vector<vector<int>> r;\n for(int i=0;i<... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n int n=nums1.size();\n int m=nums2.size();\n multiset<vector<int>>se;\n set<pair<int,int>>vis;\n int i=0,j=0;\n se.insert({nums1[i]+nums2[j],i,j});\n vector<vecto... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class comp{\n public:\n bool operator()(const vector<int> &a, const vector<int> &b){\n return a[0] > b[0];\n }\n};\nclass Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n priority_queue<vector<int>, vector<vector<int> >, c... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "/*\n他の方の回答を参考にやり直したもの\nnums1,nums2のインデックスのペアをダイクストラ法っぽく処理していく\n*/\nclass Solution {\n public:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n priority_queue<SumIndex, vector<SumIndex>, greater<SumIndex>> sum_index;\n set<vector<int>> visited;\n vector<vecto... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\n public:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n priority_queue<SumIndex, vector<SumIndex>, greater<SumIndex>> sum_index;\n set<vector<int>> visited;\n vector<vector<int>> answer;\n sum_index.push({nums1[0] + nums2[0], {0, 0}});... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n// most optimal solution\nvector<vector<int> > kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k){\n\n int n = nums1.size();\n int m = nums2.size();\n\n priority_queue< vector<int> , vector<vector<int> > , greater<vector<int> > >pq;// minheap\n\n set<vector... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n// most optimal solution\nvector<vector<int> > kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k){\n\n int n = nums1.size();\n int m = nums2.size();\n\n priority_queue< vector<int> , vector<vector<int> > , greater<vector<int> > >pq;// minheap\n\n set<vector... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\n#ifdef FIND_BY_BINARY_SEARCH\n\tint countLessOrEqual(vector<int>& nums1, vector<int>& nums2, long long mid) {\n\t\tint count = 0;\n\n \tfor (int i = 0; i < (int) nums1.size(); i++) {\n \t\tint j = (int) nums2.size() - 1;\n \t\twhile (j >= 0 && nums1[i] + nums2[j] > mid) {\n \t... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> sum_index;\n set<vector<int>> visited;\n vector<vector<int>> answer;\n sum_index.push({0, 0, 0});\n while ... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n std::vector<std::vector<int>> res;\n std::vector<int> temp;\n auto cmp = [&nums1, &nums2]\n (const std::vector<int> &p1, const std::vector<int> &p2)\n... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n std::vector<std::vector<int>> res;\n std::vector<int> temp;\n auto cmp = [&nums1, &nums2]\n (const std::vector<int> &p1, const std::vector<int> &p2)\n... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n int n = nums1.size(),m = nums2.size();\n vector<vector<int>>ans;\n priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>>pq;\n map<vector<int>,bool>... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n typedef pair<int,vector<int>> P;\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n priority_queue<P,vector<P>> maxheap;\n for(int i:nums1){\n for(int j:nums2){\n int sum=i+j;\n if(... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n class Comp {\n public:\n bool operator()(const vector<int> &a, const vector<int> &b) const {\n if (a[0] == b[0]) {\n return a[1] < b[1];\n }\n return a[0] < b[0];\n }\n };\n\n class PComp {\n pu... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\n struct comp {\n bool operator() (const vector<int> &v1, const vector<int> &v2) {\n // if (v1[2] == v2[2]) return v1[0] > v2[0];\n return v1[2] > v2[2];\n }\n };\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& num... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "typedef pair<int ,pair<int, int>> pii;\nclass Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n if(nums2.size()>nums1.size()) kSmallestPairs(nums2, nums1, k);\n priority_queue<pii, vector<pii>, greater<pii>> pq;\n for(int i=0... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n struct Values {\n public:\n int m_value = 0;\n int m_count = 0;\n std::vector<int>* m_nums = nullptr;\n\n Values() noexcept {}\n\n Values(Values const& other) noexcept : m_nums(other.m_nums), m_count(other.m_c... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n struct Values {\n public:\n int m_value = 0;\n int m_count = 0;\n std::vector<int>* m_nums = nullptr;\n\n Values() noexcept {}\n\n Values(Values const& other) noexcept : m_nums(other.m_nums), m_count(other.m_c... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n int n1 = nums1.size();\n int n2 = nums2.size();\n priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>>pq;\n pq.push({nums1[0]+nums2[0], 0, 0});\... |
373 | <p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> sorted in <strong>non-decreasing order</strong> and an integer <code>k</code>.</p>
<p>Define a pair <code>(u, v)</code> which consists of one element from the first array and one element from the second array.</p>
<p>Return <em>the</em... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>> pq;\n int i=0;\n int j=0;\n vector<vector<int>> ans;\n pq.push({nums1[0]+nums2[0],0,0}... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.