id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,553 | <p>You are given two strings, <code>coordinate1</code> and <code>coordinate2</code>, representing the coordinates of a square on an <code>8 x 8</code> chessboard.</p>
<p>Below is the chessboard for reference.</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/17/screenshot-2021-02-20-at-22159-pm.png"... | 2 | {
"code": "class Solution {\npublic:\n bool checkTwoChessboards(string coordinate1, string coordinate2) {\n int first = coordinate1[0]-96;\n int second = coordinate2[0]-96;\n int first_row = int(coordinate1[1]);\n int second_row = int(coordinate2[1]);\n printf(\"%d\",first);\n ... |
3,553 | <p>You are given two strings, <code>coordinate1</code> and <code>coordinate2</code>, representing the coordinates of a square on an <code>8 x 8</code> chessboard.</p>
<p>Below is the chessboard for reference.</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/17/screenshot-2021-02-20-at-22159-pm.png"... | 3 | {
"code": "class Solution {\npublic:\n bool checkTwoChessboards(string coordinate1, string coordinate2) {\n int first = coordinate1[0]-96;\n int second = coordinate2[0]-96;\n int first_row = int(coordinate1[1]);\n int second_row = int(coordinate2[1]);\n printf(\"%d\",first);\n ... |
3,553 | <p>You are given two strings, <code>coordinate1</code> and <code>coordinate2</code>, representing the coordinates of a square on an <code>8 x 8</code> chessboard.</p>
<p>Below is the chessboard for reference.</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/17/screenshot-2021-02-20-at-22159-pm.png"... | 3 | {
"code": "class Solution {\npublic:\n bool checkTwoChessboards(string coordinate1, string coordinate2) {\n auto getSum = [](std::string coordinate) {\n int column = coordinate[0] - 'a' + 1;\n int row = coordinate[1] - '0';\n return column + row;\n };\n \n return getSum(coordinate... |
3,553 | <p>You are given two strings, <code>coordinate1</code> and <code>coordinate2</code>, representing the coordinates of a square on an <code>8 x 8</code> chessboard.</p>
<p>Below is the chessboard for reference.</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/17/screenshot-2021-02-20-at-22159-pm.png"... | 3 | {
"code": "class Solution {\npublic:\n bool checkTwoChessboards(string coordinate1, string coordinate2) {\n string f1 = \"\", f2 = \"\";\n if(((coordinate1[0]-'a')+1)%2==0 && (coordinate1[1]-'0')%2==0 || ((coordinate1[0]-'a')+1)%2==1 && (coordinate1[1]-'0')%2==1){\n f1 = \"black\";\n ... |
3,553 | <p>You are given two strings, <code>coordinate1</code> and <code>coordinate2</code>, representing the coordinates of a square on an <code>8 x 8</code> chessboard.</p>
<p>Below is the chessboard for reference.</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/17/screenshot-2021-02-20-at-22159-pm.png"... | 3 | {
"code": "class Solution {\npublic:\n char colorofsquare(string s){\n int col=s[0]-'0';\n int row=8-(s[1]-'0');\n\n char ans='w';\n\n if(col%2==0){\n if(row%2==0){\n ans='w';\n return ans;\n }\n else{\n retur... |
3,553 | <p>You are given two strings, <code>coordinate1</code> and <code>coordinate2</code>, representing the coordinates of a square on an <code>8 x 8</code> chessboard.</p>
<p>Below is the chessboard for reference.</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/17/screenshot-2021-02-20-at-22159-pm.png"... | 3 | {
"code": "class Solution {\npublic:\n char colorofsquare(string s){\n int col=s[0]-'0';\n int row=8-(s[1]-'0');\n\n char ans='w';\n\n if(col%2==0){\n if(row%2==0){\n ans='w';\n return ans;\n }\n else{\n retur... |
3,553 | <p>You are given two strings, <code>coordinate1</code> and <code>coordinate2</code>, representing the coordinates of a square on an <code>8 x 8</code> chessboard.</p>
<p>Below is the chessboard for reference.</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/17/screenshot-2021-02-20-at-22159-pm.png"... | 3 | {
"code": "class Solution {\npublic:\n \n string find_color(string x)\n {\n string ans = \"\";\n if((x[0]-'a')%2==0)\n {\n if(x[1]%2==0)\n ans = \"white\";\n else\n ans = \"black\";\n }\n else\n {\n if(x[1... |
3,553 | <p>You are given two strings, <code>coordinate1</code> and <code>coordinate2</code>, representing the coordinates of a square on an <code>8 x 8</code> chessboard.</p>
<p>Below is the chessboard for reference.</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/17/screenshot-2021-02-20-at-22159-pm.png"... | 3 | {
"code": "class Solution {\npublic:\n bool checkTwoChessboards(string coordinate1, string coordinate2) {\n vector<vector<int>> chess(8, vector<int>(8));\n for(int i=0;i<8;i++)\n {\n for(int j=0;j<8;j++)\n {\n if(i%2==0)\n {\n ... |
3,553 | <p>You are given two strings, <code>coordinate1</code> and <code>coordinate2</code>, representing the coordinates of a square on an <code>8 x 8</code> chessboard.</p>
<p>Below is the chessboard for reference.</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/17/screenshot-2021-02-20-at-22159-pm.png"... | 3 | {
"code": "class Solution {\npublic:\n bool checkTwoChessboards(string coordinate1, string coordinate2) \n {\n set<char>black;\n set<char>white;\n int c=0;\n for(char ch='a';ch<='h';ch++)\n {\n if(c%2==0)\n {\n black.insert(ch);\n }\... |
3,553 | <p>You are given two strings, <code>coordinate1</code> and <code>coordinate2</code>, representing the coordinates of a square on an <code>8 x 8</code> chessboard.</p>
<p>Below is the chessboard for reference.</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/17/screenshot-2021-02-20-at-22159-pm.png"... | 3 | {
"code": "class Solution {\npublic:\n bool checkTwoChessboards(string c1, string c2) {\n unordered_set<char> aceg = {'a', 'c', 'e', 'g'};\n int c1color = 0;\n int c2color = 0;\n if(aceg.find(c1[0]) != aceg.end()){\n if(c1[1]%2 != 0){\n c1color = 0;\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 0 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n std::vector<int> result;\n const int n = queries.size();\n result.reserve(n);\n int h[k];\n for (int i = 0; i<k && i<n; ++i) {\n int v = abs(queries[i][0]) + abs(qu... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 0 | {
"code": "priority_queue<int> que;\n\nclass Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int n = queries.size();\n while (!que.empty()) {\n que.pop();\n }\n vector<int> ret(n);\n for (int i = 0; i < n; ++i) {\n int x = queries[i][0]... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 0 | {
"code": "#include <iostream>\n#include <vector>\n#include <fstream>\n\ntemplate <typename T, typename Comparator>\nclass Pyramid {\nprivate:\n std::vector<T> array;\n Comparator comparator;\n int size;\n\n int left_child(int index);\n\n int right_child(int index);\n\n int parent(int index);\n\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 0 | {
"code": "#include <iostream>\n#include <vector>\n#include <fstream>\n\ntemplate <typename T, typename Comparator>\nclass Pyramid {\nprivate:\n std::vector<T> array;\n Comparator comparator;\n int size;\n\n int left_child(int index);\n\n int right_child(int index);\n\n int parent(int index);\n\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 0 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n if (queries.size() < k) {\n return vector<int>(queries.size(), -1);\n }\n\n int pq[k];\n transform(queries.begin(), next(queries.begin(), k), pq, calcDistance);\n m... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 0 | {
"code": "\nclass Solution {\npublic:\n\ntemplate<class T, class U = greater<T>> class p_queue { vector<T> H; U Cc; size_t S = 0, C;\n void H_U(size_t I) { while (I && Cc(H[I], H[(I - 1) >> 1])) { swap(H[I], H[(I - 1) >> 1]); I = (I - 1) >> 1; }}\n void H_D(size_t I) { while (true) { size_t Lrg = I, L = 2 * I ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 0 | {
"code": "\nclass Solution {\npublic:\n\ntemplate<class T, class U = greater<T>> class p_queue { vector<T> H; U Cc; size_t S = 0, C;\n void H_U(size_t I) { while (I && Cc(H[I], H[(I - 1) >> 1])) { swap(H[I], H[(I - 1) >> 1]); I = (I - 1) >> 1; }}\n void H_D(size_t I) { while (true) { size_t Lrg = I, L = 2 * I ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 0 | {
"code": "class Solution {\npublic:\n\n void swim(vector<int>& vec, int idx) {\n while(idx > 0) {\n int parent_idx = (idx-1)/2;\n if (vec[idx] > vec[parent_idx]) {\n swap(vec[idx], vec[parent_idx]);\n idx = parent_idx;\n }else\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 0 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int n=queries.size();\n priority_queue<int>dist;\n vector<int>res(n);\n for(int i=0;i<n;i++){\n dist.push(abs(queries[i][0])+abs(queries[i][1]));\n if(dist.size... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 0 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<int> q;\n vector<int> ans(queries.size(), -1);\n for (int i = 0; i < queries.size(); ++i) {\n int cur_dis = abs(queries[i][0]) + abs(queries[i][1]);\n i... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 0 | {
"code": "#include <iostream>\n#include <queue>\n\nstatic const int fast_io = []()\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(NULL);\n std::cout.tie(NULL);\n return 0;\n}();\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 0 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n\n priority_queue<int> pq;\n vector<int> ans(queries.size(), -1);\n if (k > queries.size()) {\n return... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 0 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n // priority_queue<int,vector<int>,greater<int>>pq;\n priority_queue<int>pq;\n int n=queries.size();\n vector<int>ans(n);\n vector<int>store(k);\n int now=-1;\n f... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 0 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n std::vector<int> kNearDistObst, ans;\n kNearDistObst.reserve(k+1);\n int dist = -1;\n std::make_heap(kNearDistObst.begin(), kNearDistObst.end());\n for(auto &query : queries)\... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL); \n priority_queue<int> pq;\n vector<int> res;\n for (int i=0; i<queries.size(); i++) {\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n vector<int> ans;\n \n vector<int> d;\n \n if(k>queries.size()){\n for(int i=0; i<queries.size(); i++){\n ans.push_back(-1);\n }\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "template <typename T>\nstruct Fenwick {\n\tint n;\n\tvector<T> a;\n\n\tFenwick(int n = 0) {\n\t\tinit(n);\n\t}\n\n\tvoid init(int n) {\n\t\tthis->n = n;\n\t\ta.assign(n + 1, T());\n\t}\n\n\tvoid add(int i, T val) {\n\t\tfor (++i; i <= n; i += i & -i) {\n\t\t\ta[i] += val;\n\t\t}\n\t}\n\n\tT query(int i) {\... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n vector<int> result(queries.size());\n int n = queries.size();\n if(n == 1 && k == 1){\n return {abs(queries[0][0]) + abs(queries[0][1])};\n }\n if(k > n){\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int n=queries.size();\n vector<int> result(n);\n priority_queue<pair<int,pair<int,int>>> pq;\n for(int i=0;i<n;i++){\n int dist=abs(queries[i][0])+abs(queries[i][1]);\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n // max heap with size k\n // min heap with other\n priority_queue<int> max_heap;\n priority_queue<int, vector<int>, greater<int>> min_heap;\n vector<int> result(queries.size()... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<long long>pq;\n int n = queries.size();\n vector<int>ans;\n if(n<k){\n for(int i=0;i<n;i++)ans.push_back(-1);\n return ans;\n }\n f... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\nprivate:\n // int lesser (map<int,int>&distCount,int dist)\n // {\n // int ans =0;\n // for(auto it = distCount.begin();it!=distCount.end();it++)\n // {\n // if(it->first>=dist)return ans;\n // else ans += it->second;\n // }\n // ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<int> pq1, pq2;\n vector<int>res;\n int n = queries.size();\n for(int i = 0 ;i < n; i++){\n int d = abs(queries[i][0])+abs(queries[i][1]);\n pq1.p... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int m = queries.size();\n int n = queries[0].size();\n vector <int> ans;\n // for(int i=0;i<k-1;i++) ans.push_back(-1);\n vector <long long> temp(m);\n for(int i=0;i<m;... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "bool comparator(pair<int, int>& p1, pair<int, int>& p2) {\n if (p1.first == p2.first) {\n return p2.second < p1.second;\n }\n return p1.first < p2.first;\n }\n\nclass Solution {\n \n\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int q = queries.size();\n vector<int> res(q , -1);\n priority_queue<pair<long long, int>> pq;\n \n for(int i = 0; i < q; i++){\n pq.push({abs(queries[i][0]) + abs(q... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\nprivate:\n priority_queue<long long> maxHeap;\n priority_queue<long long, vector<long long>, greater<long long>> minHeap;\n int K;\n\n void addObstacle(long long distance) {\n if (maxHeap.size() < K) {\n maxHeap.push(distance);\n } else if (distance < ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue <pair<int,pair<int, int>>> p;\n vector <int> ans;\n for(int i = 0; i < queries.size(); i++){\n if(p.size() == k){\n auto it = p.top();\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n int dist(int x,int y){\n return abs(x)+abs(y);\n }\n\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n vector<int> ans;\n priority_queue<pair<int,pair<int,int>>> pq;\n for(int i=0;i<queries.size();i++){\n int x=qu... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n long long int dis(long long int a, long long int b){\n return abs(a) + abs(b); \n }\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n vector<int> ans;\n vector<long long int> arr(queries.size(),-1);\n for(int i = 0; ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int n=queries.size(),i=0;\n vector<int>ans(n,-1);\n priority_queue<int>pq;\n if(k>n){\n return ans;\n }\n\n int l=0;\n for(auto it:queries){\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue <pair<long long,int>> pq;\n\n vector <int> ans;\n for(int i = 0 ; i < queries.size() ; i++) {\n int r = queries[i][0] , c = queries[i][1];\n\n pq.push({... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n \n void output(vector<int> vec) {\n for(int i = 0; i < vec.size(); i++) {\n cout << vec.at(i) << \", \";\n }\n cout << endl;\n }\n \n vector<int> edgeCase1(int size) {\n vector<int> results;\n for(int i = 0; i < size; ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\nstruct comp1{\n bool operator()(pair<int,long long>&p1, pair<int, long long>&p2)\n {\n if(p1.second>p2.second)return true;\n return false;\n }\n};\nstruct comp2{\n bool operator()(pair<int,long long>&p1, pair<int, long long>&p2)\n {\n if(p1.sec... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int n = queries.size();\n priority_queue<long double> closestK;\n vector<int> out;\n for(int i = 0; i < n; i++) {\n int dist = abs(queries[i][0]) + abs(queries[i][1]);\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n typedef long long ll;\n\n int find_dist(int x, int y) {\n return abs(x)+abs(y);\n }\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n //kth nearest distance\n\n //2 heaps?\n priority_queue<ll> leftHeap;\n priority_... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<long long,vector<long long>,greater<long long>> sq;\n priority_queue<long long> lq;\n vector<int> ans;\n int q=queries.size();\n for(int i=0;i<q;i++){\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n inline int abs(int x) {return x>0? x: -x;}\n \n int ask(vector<int> &arr, int pos) {\n int ans = 0;\n for(; pos; pos -= pos & (-pos))\n ans += arr[pos];\n return ans;\n }\n void add(vector<int> &arr, int pos, int val = 1) {\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n inline int abs(int x) {return x>0? x: -x;}\n \n int ask(vector<int> &arr, int pos) {\n int ans = 0;\n for(; pos; pos -= pos & (-pos))\n ans += arr[pos];\n return ans;\n }\n void add(vector<int> &arr, int pos, int val = 1) {\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n inline int abs(int x) {return x>0? x: -x;}\n \n int ask(vector<int> &arr, int pos) {\n int ans = 0;\n for(; pos; pos -= pos & (-pos))\n ans += arr[pos];\n return ans;\n }\n void add(vector<int> &arr, int pos, int val = 1) {\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\n#define xl cout<<'\\n';\n#define def template<typename... T>\n\ndef void out(T&&... s) {\n\t(void)initializer_list<int> {(cout << s << '\\n', 0)...};\n}\ndef void outc(T&&... s) {\n\t(void)initializer_list<int> {(cout << s << \" \", 0)...};\n}\ndef void out... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n vector<int>result;\n priority_queue<int>max;\n vector<pair<int,int>>obsv;\n for(const auto &i:queries)\n {\n int a=i[0],b=i[1];\n int dist=abs(a)+abs(b);... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n vector<int> res;\n priority_queue<int>maxH;\n vector<pair<int,int>> obs;\n for(const auto &query:queries)\n {\n int x=query[0],y=query[1];\n int dis=abs(... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n \n int dis(int a,int b){\n // int abs_dist = abs(a)+abs(b);\n return abs(a)+abs(b);\n \n }\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n vector<int>res;\n \n vector<pair<int,int>>obs;\n priority_q... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n\n void replace(vector<int>& rsq, int mod, int i, int x) {\n i += mod;\n rsq[i] = x;\n i /= 2;\n while (i > 0) {\n rsq[i] = rsq[i + i] + rsq[i + i + 1];\n i /= 2;\n }\n }\n\n int getsum(vector<int>& rsq, int mod, i... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\ntemplate <typename T>\nvoid print(const T& container, const std::string& delimiter = \" \") {\n std::copy(container.begin(), container.end(), std::ostream_iterator<typename T::value_type>(std::cout, delimiter.c_str()));\n std::cout << std:... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<long long>pq;\n vector<long long>arr;\n for(int i=0;i<queries.size();i++){\n arr.push_back(abs(queries[i][0])+abs(queries[i][1]));\n }\n vector<int>... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n vector<long long int> distance;\n vector<int> ans;\n priority_queue<long long> pq;\n\n for(int i=0;i<queries.size();i++)\n {\n long long int dist = abs(queries[i][0... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "#define ll long long int\nclass Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n ll n=queries.size();\n vector<ll> ans;\n priority_queue<ll> pq;\n for(ll i=0;i<n;i++){\n ll x=queries[i][0];\n ll y=queries[i][1];\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& q, int k) {\n vector<int> ans ;\n priority_queue<long long> pq ;\n for(int i = 0 ; i < q.size() ; i++) {\n long long x = q[i][0] ;\n long long y = q[i][1] ;\n long long dis = a... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& q, int k) {\n vector<int> ans ;\n priority_queue<long long> pq ;\n for(int i = 0 ; i < q.size() ; i++) {\n long long x = q[i][0] ;\n long long y = q[i][1] ;\n long long dis = a... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) \n {\n const size_t size = queries.size();\n vector<int> records(size, 0);\n for (int i = 0; i < size; ++i)\n {\n records[i] = abs(queries[i][0]) + abs(queries[i][1]);\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> solve(vector<vector<int>>& queries, int k) {\n vector<int> ans;\n priority_queue<int> pq;\n unordered_set<int> st;\n\n for (const auto& it : queries) {\n\n pq.push(abs(it[0]) + abs(it[1]));\n \n if (pq.s... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<int> pq;\n vector<int> ret(queries.size(), -1);\n if (k > queries.size()) return ret;\n\n int index = k - 1;\n for (auto query : queries) {\n int dis... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n //As we need to find the kth nearest distance we have to create a max heap of the size k;\n priority_queue<int>pq;\n vector<int>ans(queries.size());\n int index=0;\n for(auto ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int len = queries.size();\n priority_queue<int> left; // get the largest num\n vector<int> result = vector(len, -1);\n // let left.size() == k\n for(int i = 0; i < len; i++){\... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n \n int N = queries.size();\n \n priority_queue<int> store;\n vector<int> answer(N, -1);\n \n int index = 0;\n // 3 ,7, 5 ,3 , 18\n for(auto query :... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<int>pq;\n int n = queries.size();\n vector<int>v(n,-1);\n for(int i=0;i<n;i++){\n auto it = queries[i];\n int x = it[0];\n int y = it[... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<int>pq;\n int n=queries.size();\n vector<int> ans(n,-1);\n int temp=k;\n for(auto qry:queries) {\n if(k) {\n pq.push(abs(qry[0]) + abs... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n \n \n \n vector<int> resultsArray(vector<vector<int>>& q, int k) {\n \n \n priority_queue<int> pq;\n vector<int> ans;\n set<int> st;\n for(int i=0;i<q.size();i++){\n \n int val = abs(q[i][0]) + abs(q[i][1]) ;... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n template<typename T> struct Tr_Nd {\n T key; int32_t Hg, count, Sz; Tr_Nd* Lt; Tr_Nd* Rt;\n Tr_Nd(T x) : key(x), Lt(nullptr), Rt(nullptr), Hg(1), count(1), Sz(1) {}\n};\ntemplate<typename T> class mset {\n Tr_Nd<T>* root; int32_t cnt = 0; T first = numeric_limits<T>:... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n template<typename T> struct Tr_Nd {\n T key; int32_t Hg, count, Sz; Tr_Nd* Lt; Tr_Nd* Rt;\n Tr_Nd(T x) : key(x), Lt(nullptr), Rt(nullptr), Hg(1), count(1), Sz(1) {}\n};\ntemplate<typename T> class mset {\n Tr_Nd<T>* root; int32_t cnt = 0; T first = numeric_limits<T>:... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "struct AVLNode {\n int value, subtreeSize;\n AVLNode *left, *right;\n\n AVLNode() {}\n\n AVLNode(int Value, \n int SubtreeSize = 1, \n AVLNode *Left = nullptr, \n AVLNode *Right = nullptr\n ): value(Value), subtreeSize(SubtreeSize), left(Left), right(Righ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n multiset<int> st;\n priority_queue<int> pq;\n vector<int> ans;\n for(int i=0;i<min(k-1,(int)queries.size());i++){\n ans.push_back(-1);\n pq.push(abs(queries[i][... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n vector<int>anse(queries.size(),-1);\n if(k>queries.size()){\n return anse;\n }\n priority_queue<int>pq;\n vector<int>ans(queries.size());\n int ind=0;\n f... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<long> pq;\n int n = queries.size();\n vector<int> ans(n, -1);\n if(k > n) return ans;\n for(int i=0; i<n; i++){\n auto q = queries[i];\n l... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<long> pq;\n int n = queries.size();\n vector<int> ans(n, -1);\n if(k > n) return ans;\n for(int i=0; i<n; i++){\n auto q = queries[i];\n l... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int n=queries.size();\n vector<int>ans(n,-1);\n \n priority_queue<long long>s;\n for(int i=0;i<n;i++){\n auto it=queries[i];\n s.push(abs(it[0])+abs(it[1... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<int,vector<int>>pq;\n vector<int>res;\n for(auto it:queries){\n int x=it[0];\n int y=it[1];\n if(pq.empty()||pq.size()<k){\n p... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 2 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int n=queries.size();\n\n priority_queue<int> pq;\n vector<int> ans;\n for(auto query:queries){\n int dist=abs(query[0]) + abs(query[1]);\n\n while(pq.size()>=k... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n std::ios_base::sync_with_stdio(false);std::cin.tie(nullptr);\n int n=queries.size();\n priority_queue<int>pq;\n vector<int>result;\n for(auto it:queries){\n int dis... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "#include <bits/stdc++.h>\nclass Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n vector<int> res;\n\n for(auto q:queries){\n int a=abs(q[0]), b=abs(q[1]);\n int lo=0,hi=res.size();\n int x=a+b;\n res.push_ba... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "class Solution {\npublic:\n vector<int> ans;\n priority_queue<int> pq;\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n for(auto x: queries){\n int dist= abs(x[0])+ abs(x[1]);\n if(pq.size()<k) pq.push(dist);\n else if(dist < pq.top()){\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& q, int k) {\n vector<int>v;\n for(auto x:q){\n v.push_back(abs(x[0])+abs(x[1]));\n }\n priority_queue<int>pq;\n vector<int>ans(q.size());\n for(int i=0;i<q.size();++i){\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "#define piii pair<int, pair<int, int>>\nstruct myCmp{\n bool operator()(piii& a, piii& b){\n return a.first < b.first;\n }\n};\nclass Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int n = queries.size();\n priority_queue<piii, vector<p... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) \n {\n priority_queue< pair<int,pair<int,int>> > q;\n vector<int> ans;\n\n for(auto query : queries)\n {\n int x = query[0];\n int y = query[1];\n\n i... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<pair<int, pair<int, int>>> pq;\n vector<int>ans;\n for(auto point: queries)\n {\n int dist = abs(point[0]) + abs(point[1]);\n pq.push({dist, {poi... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<pair<int, pair<int, int>>> distances; // (distance, (x, y))\n vector<int> result;\n for (auto query : queries) {\n auto x = query[0]; auto y = query[1];\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "struct Obstacle\n{\n int x, y;\n int d;\n\n Obstacle(int _x, int _y)\n {\n x = _x;\n y = _y;\n d = abs(x) + abs(y);\n }\n};\n\nlong distance(Obstacle &a)\n{\n return abs(a.x) + abs(a.y);\n}\n\nbool operator <(Obstacle a, Obstacle b)\n{\n return distance(a) < distance(b);\n}\n\nclass Solutio... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n vector<int> nums;\n for(auto a:queries) {\n int sum = abs(a[0]);\n sum += abs(a[1]);\n\n nums.push_back(sum);\n }\n\n priority_queue<int> maxHeap;\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<int> max_heap;\n unordered_set<int> distance_set;\n vector<int> results;\n\n for (const auto& query : queries) {\n int x = query[0];\n int y = query[1];\n int... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& q, int k) {\n vector<int> ans;\n priority_queue<int> m;\n unordered_set<int> d;\n for (const auto& query : q) {\n int x = query[0];\n int y = query[1];\n int dist = abs(... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n set<int> st;\n vector<pair<int,int>> v;\n int i = 0;\n int n = queries.size();\n priority_queue<int> pq;\n for(auto it: queries){\n pq.push(abs(it[0])+abs(it[1... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "#define ll long long\nclass Solution {\n\n ll dist(vector<int> &point) {\n return abs(point[0]) + abs(point[1]);\n }\n\n\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<pair<ll,ll>> small;\n \n int idx = 0;\n vector<int... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "class Solution {\npublic:\n // long long get_dis(long long a) {\n // return a * a;\n // }\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<pair<long long, int>> pq;\n vector<int> ans;\n for (int i = 0; i < queries.size(); i++) {\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "#define debug(...) debug_helper (#__VA_ARGS__, __VA_ARGS__)\n#define cerr cout\n\n//Used to print value of variable(s) at a given point in time\ntemplate <typename Arg1>\nvoid debug_helper (const char* name, Arg1&& arg1) {\n\tcerr << name << \" : \" << arg1 << endl;\n}\n\ntemplate <typename Arg1, typename.... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n int n = queries.size(), i;\n vector<int> ans(n, -1);\n if(k > n)\n return ans;\n priority_queue<vector<int>> pq;\n for(i=0;i<k; i++)\n pq.push({(abs(queries[i][0... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "class Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n priority_queue<vector<int>, vector<vector<int>>, cmp> pq;\n int n = queries.size();\n vector<int> result(n, -1);\n for (int i = 0; i < n; i++) {\n pq.push(queries[i]);\n ... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n auto queries_size = queries.size();\n if (static_cast<int>(queries_size) < k) {\n return std::vector<int>(queries_size, -1);\n }\n... |
3,495 | <p>There is an infinite 2D plane.</p>
<p>You are given a positive integer <code>k</code>. You are also given a 2D array <code>queries</code>, which contains the following queries:</p>
<ul>
<li><code>queries[i] = [x, y]</code>: Build an obstacle at coordinate <code>(x, y)</code> in the plane. It is guaranteed that th... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> resultsArray(vector<vector<int>>& queries, int k) {\n auto queries_size = queries.size();\n if (static_cast<int>(queries_size) < k) {\n return std::vector<int>(queries_size, -1);\n }\n... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.