id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
0
{ "code": "class Solution {\npublic:\n static bool compare (vector<int>& a, vector<int>& b) {\n if (a[0] != b[0]) return a[0] < b[0];\n return a[0] < b[0];\n }\n\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n int n = people.size();\n sort(people.begin(), p...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n std::vector<std::vector<int>> ans(people.size(), {-1, 1});\n\n std::sort(people.begin(), people.end());\n\n int height = -1, head = 0, tail = people.size(), cur = 0, i = 0;\n for...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n int peopleSize = people.size();\n vector<vector<int>> ans(peopleSize);\n sort(people.begin(), people.end());\n for(int index=0;index<people.size();index++){\n int grea...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
0
{ "code": "class Solution {\npublic:\n // Comparator function\n static bool compare(const vector<int>& a, const vector<int>& b) {\n if (a[0] == b[0]) {\n return a[1] < b[1]; \n }\n return a[0] > b[0]; \n }\n\n vector<vector<int>> reconstructQueue(vector<vector<int>>& peop...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n auto cmp = [&](const vector<int>& a, const vector<int>& b) {\n return a[0] == b[0] ? a[1] < b[1] : a[0] > b[0];\n };\n sort(people.begin(), people.end(), cmp);\n\n //i...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
0
{ "code": "class BIT {\nprivate:\n int size;\n vector<int> bit;\n \npublic:\n BIT (int n) : size(n), bit(n, 0) {\n for (int i = 0; i < size; i++) {\n add(i, 1);\n }\n }\n\n void add(int idx, int val) {\n for (; idx < size; idx |= (idx + 1)) {\n bit[idx] += ...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n std::sort(people.begin(), people.end());\n vector<vector<int>> result(people.size(), {-1,-1});\n for(const auto& p : people) {\n int i = 0;\n for(int skipped = 0; ...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
0
{ "code": "struct lessThanComp{\n bool operator()(const vector<int>&a1 , const vector<int> &a2){\n if(a1[0] == a2[0]){\n return a1[1] < a2[1];\n }\n else{\n return a1[0] < a2[0];\n }\n }\n};\nclass Solution {\npublic:\n vector<vector<int>> rec...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
1
{ "code": "#include <vector>\n#include <algorithm>\n\nclass Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n // Sort people by descending height and then by ascending k values\n std::sort(people.begin(), people.end(), [](const vector<int>& a, const vector<in...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
1
{ "code": "class Solution {\n int n;\n int getNext(int val){\n return val + (val&-val);\n }\n\n int getParent(int val){\n return val - (val&-val);\n }\n\n void update(vector<int>& tree, int index, int val){\n if(index>=tree.size()){\n return;\n }\n tree[...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
1
{ "code": "class Solution {\npublic:\n vector<int> tree;\n int build(int node, int start, int end) {\n if(start == end) {\n tree[node - 1] = 1;\n return 1;\n }\n int mid = (start + end) / 2;\n int left = build(node * 2, start, mid);\n int right = build(no...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n vector<vector<int>> ans;\n // Sort by height in descending order, if same height then by the number of people in ascending order\n sort(people.begin(), people.end(), [](const vector<int...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n int n = people.size();\n if (n == 1) return people;\n // sort the queue by how many higher people in front\n sort(people.begin(), people.end(), [] (const vector<int>& a, const ve...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n vector<vector<int>> ans;\n // Sort by height in descending order, if same height then by the number of people in ascending order\n sort(people.begin(), people.end(), [](const vector<int...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n vector<vector<int>> ans;\n // Sort by height in descending order, if same height then by the number of people in ascending order\n sort(people.begin(), people.end(), [](const vector<int...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
2
{ "code": "class Solution {\npublic:\n static bool compare(vector<int> &a,vector<int> &b){\n if(a[0]==b[0])\n return a[1]<b[1];\n return a[0]>b[0];\n }\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n vector<vector<int>> ans;\n sort(people.begin()...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
2
{ "code": "class Solution {\n //[[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]\n // [70][71][61][50][52][44]\n\n // vAns = 50 70 52 61 44 71 \n\n static bool customSort(std::vector<int>& v1, std::vector<int>& v2)\n {\n if (v1[0] > v2[0])\n return true;\n\n if (v1[0]== v2[0] && v1[1] < v2[1]...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n sort(people.begin(), people.end(), [](vector<int> const& a, vector<int> const& b) {\n if (a[0] != b[0]) { return a[0] > b[0]; }\n return a[1] < b[1];\n});\n\nusing entry = pair<int, int>;\nlist...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>> > pq;\n for (auto pair: people){\n pq.push({pair[0], pair[1]});\n }\n int n=people.size(...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n vector<vector<int>> temp = people;\n vector<vector<int>> result;\n\n auto comp = [](pair<int, int> a, pair<int, int> b) {\n return a.first > b.first;\n };\n pri...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
2
{ "code": "// vector动态数组insert的时间复杂度高\n// 用底层为链表实现的list容器更快\nclass Solution {\npublic:\n static bool cmp(vector<int>& a, vector<int>& b) {\n if (a[0] == b[0]) return a[1] < b[1]; // 身高相等,前面人少的优先\n return a[0] > b[0]; // 高的优先\n }\n vector<vector<int>> reconstructQueue(vector<vector<int>>& pe...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
2
{ "code": "#include <list>\n\nclass Solution {\n #pragma GCC optimize(\"O3\")\n\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) \n {\n sort(people.begin(), people.end(), [] (const vector<int>& a, const vector<int>& b) \n {\n if (a[0] == b[0])\n ...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
2
{ "code": "bool cmp(vector<int>& personA, vector<int>& personB){\n if(personA[0] == personB[0])return personA[1] > personB[1];\n else return personA[0] < personB[0];\n};\n\nint getNthIndex(\n unordered_map<int, int>& takenPositions,\n int n, \n int k\n){\n int count = 0;\n for(int position = 0; p...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>>v;\n vector<int>t;\n int gI(int i, int sp, int st, int en){\n if(st == en) return st;\n else{\n int mid = (st+en)/2;\n int w = mid-st+1;\n int l = t[2*i+1];\n int r = t[2*(i+1)];\n\n ...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n\n static bool cmp (const vector<int> & A, const vector<int> & B) {\n if (A[0] == B[0]) return A[1] <B[1];\n return A[0] > B[0];\n }\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n sort(people.begin(), people.end(), cmp);\n ...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\n struct comp{ \n template <typename T>\n bool operator()(const T& e1, const T& e2)const{\n if(e1[0]==e2[0]){\n return e1[1] < e2[1];\n }\n return e1[0] > e2[0];\n }\n };\npublic:\n vector<vector<int>> reconstr...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> pq;\n int n = people.size();\n vector<vector<int>> copy = people;\n vector<vector<int>> res;\n for(i...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n static bool cmp(vector<int>& a, vector<int>& b){\n if(a[0] == b[0]) return a[1] < b[1];\n else return a[0] > b[0];\n }\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n sort(people.begin(), people.end(), cmp);\n list<vec...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n\n static bool comparator(vector<int> &a, vector<int> &b){\n if( a[0] != b[0])\n return a[0] > b[0];\n return a[1] < b[1];\n }\n\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n sort(people.begin(),people.end(), comp...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n struct compare{\n bool operator()(vector<int>&a, vector<int>&b){\n if(a[0]==b[0])\n return a[1]>b[1];\n return a[0]<b[0];\n }\n };\n \n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n int n=people.size();\...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n static bool cond(pair<int, int> a, pair<int, int> b) {\n if (a.second != b.second) {\n return a.second < b.second;\n }\n return a.first < b.first;\n }\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n vector<p...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n const int n = people.size();\n sort(people.begin(), people.end(), [](auto &a, auto &b) {\n return a[0] > b[0] || (a[0] == b[0] && a[1] < b[1]);\n });\n list<vector<int...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n/*See editorial*/\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n const int n = people.size();\n sort(people.begin(), people.end(), [](auto &a, auto &b) {\n return a[0] > b[0] || (a[0] == b[0] && a[1] < b[1]);\n });\n ...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n map<int, set<int>> pos_to_ordered_height_map;\n for (const auto& person: people) {\n const int height = person[0];\n const int num_people = person[1]; \n pos_t...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n map<int, set<int>> pos_to_ordered_height_map;\n for (const auto& person: people) {\n const int height = person[0];\n const int num_people = person[1]; \n pos_t...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n map<int, set<int>> pos_to_ordered_height_map;\n for (const auto& person: people) {\n const int height = person[0];\n const int num_people = person[1]; \n pos_t...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n map<int, set<int>> pos_to_ordered_height_map;\n for (const auto& person: people) {\n const int height = person[0];\n const int num_people = person[1]; \n pos_t...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n map<int, set<int>> pos_to_ordered_height_map;\n for (const auto& person: people) {\n const int height = person[0];\n const int num_people = person[1]; \n pos_t...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n priority_queue<vector<int>> pq;\n for (auto &it: people) {\n pq.push({it[1], it[0]});\n }\n vector<vector<int>> sorted;\n while (!pq.empty()) {\n sor...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "/*********************** Chandrachur Mukherjee ***********************/\n\n#include<bits/stdc++.h>\n// #include<ext/pb_ds/assoc_container.hpp>\n// #include<ext/pb_ds/tree_policy.hpp>\n\nusing namespace std; \nusing namespace chrono;\n// using namespace __gnu_pbds;\n\n#define fastio() ios_base::sync_with_st...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& p)\n {\n map<int,vector<int>>m;\n //number and index number\n for(int i=0;i<p.size();i++)\n {\n m[p[i][0]].push_back(p[i][1]);\n }\n int ...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& p)\n {\n sort(p.begin(),p.end());\n // cout<<\" p is \"<<endl;\n // for(int i=0;i<p.size();i++)\n // {\n // cout<<p[i][0]<<\" \"<<p[i][1]<<endl;\n // }\n ...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n map<int, set<int>> mp;\n for(auto it : people){\n mp[it[1]].insert(it[0]);\n }\n vector<vector<int>> res ;\n for(int i = 0 ;i < people.size();i++){\n ...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n map<int, set<int>> mp;\n for(auto it : people){\n mp[it[1]].insert(it[0]);\n }\n vector<vector<int>> res ;\n for(int i = 0 ;i < people.size();i++){\n ...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\n\nprivate: \n static bool compare(vector<int>& A, vector<int>& B){\n \n if(A[0] == B[0]){\n return A[1] < B[1];\n }\n return A[0] > B[0];\n \n }\n\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n ...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n map<int, set<int>> mp;\n for (auto a : people) {\n mp[a[0]].insert(a[1]);\n }\n vector<vector<int>> res;\n for (auto it = mp.rbegin(); it != mp.rend(); ++it) {\...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "static auto _ = [](){\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return nullptr;\n}();\n\n#pragma GCC optimize(\"tree-vectorize\")\n#pragma GCC target(\"tune=native\")\n#pragma GCC optimize(\"Ofast\")\n\n\nclass Solution {\npublic:\n std::vector<...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "static auto _ = [](){\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return nullptr;\n}();\n\n#pragma GCC optimize(\"tree-vectorize\")\n#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"avx2\")\n\n\nclass Solution {\npublic:\n std::vector<std::ve...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "static auto _ = [](){\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return nullptr;\n}();\n\n#pragma GCC optimize(\"tree-vectorize\")\n#pragma GCC target(\"tune=native\")\n#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"avx2\")\n\n\nclass Solutio...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "#include<list>\nclass Solution {\npublic:\n \n static bool customComparator(vector<int>& v1, vector<int>& v2) {\n bool verdict = false;\n if (v1[1] < v2[1]) {\n verdict = true;\n }\n else if (v2[1] < v1[1]) {\n verdict = false;\n }\n els...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n static bool cmp(const vector<int> &a, vector<int>b)\n {\n if (a[0] == b[0]) return a[1] < b[1];\n return a[0] > b[0];\n }\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n\n int size = people.size();\n vector<vector<i...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n static bool cmp(vector<int> &a, vector<int>b)\n {\n if (a[0] == b[0]) return a[1] < b[1];\n return a[0] > b[0];\n }\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n\n int size = people.size();\n vector<vector<int>> a...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n std::vector<std::vector<int>> reconstructQueue(std::vector<std::vector<int>>& people) \n {\n std::sort( people.begin(), people.end(), []( std::vector<int>first, std::vector<int>& second ){\n return first[0] == second[0] ? first[1] < second[1] : first[0] >...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n std::vector<std::vector<int>> reconstructQueue(std::vector<std::vector<int>>& people) \n {\n std::sort( people.begin(), people.end(), []( std::vector<int>first, std::vector<int>& second ){\n return first[0] == second[0] ? first[1] < second[1] : first[0] >...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n static bool cmp(const vector<int> &a,const vector<int>b)\n {\n if (a[0] == b[0]) return a[1] < b[1];\n return a[0] > b[0];\n }\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n\n int size = people.size();\n vector<ve...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n sort(people.begin(), people.end(), [](const vector<int> & a, const vector<int>b){\n if(a[0]!=b[0]){\n return a[0]>b[0];\n }\n return a[1]<b[1];\n ...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n int n=people.size();\n new_sort(people);\n vector<int> v(n);\n vector<int> r;\n for(int i=0;i<v.size();i++){\n if(people[i][1]==0){\n v[i]=1;\n ...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n constexpr static int maxH=1048576;\n constexpr static int maxN=2001;\n int tree[2*maxH];\n int used[maxN];\n void update(int pos,int val){\n pos+=maxH;\n tree[pos]+=val;\n pos/=2;\n while(pos){\n tree[pos]=tree[2*pos]+tree[2*...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n #define n 1000001\n int segTree[2*n];\n void update(int i){\n i+=n;\n segTree[i]++;\n for(i;i>1;i>>=1)segTree[i>>1]=segTree[i]+segTree[i^1];\n }\n int query(int l,long r){\n int sum=0;\n for(l+=n,r+=n;l<r;l>>=1,r>>=1){\n ...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n int n = people.size();\n auto comp = [](vector<int> x, vector<int> y) {\n if (x[0] == y[0]) {\n return x[1] > y[1];\n }\n return x[0] > y[0];\n ...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n bool static mycomp(vector<int>v1, vector<int>v2){\n if(v1[0] != v2[0]){\n return v1[0]<v2[0];\n }\n else{\n return v1[1] < v2[1];\n }\n }\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n sor...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n static bool compare(vector<int> a, vector<int> b)\n {\n if(a[0] == b[0])\n return b[1] < a[1];\n \n return a[0] < b[0];\n }\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) \n {\n sort(people.begin(),people...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n bool static mycomp(vector<int>v1, vector<int>v2){\n if(v1[0] != v2[0]){\n return v1[0]<v2[0];\n }\n else{\n return v1[1] < v2[1];\n }\n }\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n sor...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<int>tree;\n void build(int node,int start,int end) {\n if(start==end) {\n tree[node]=1; \n return;\n }\n int mid=(start+end)/2;\n build(2*node,start,mid);\n build(2*node+1,mid+1,end);\n tree[node]=tree[...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<int>tree;\n void build(int node,int start,int end) {\n if(start==end) {\n tree[node]=1; \n return;\n }\n int mid=(start+end)/2;\n build(2*node,start,mid);\n build(2*node+1,mid+1,end);\n tree[node]=tree[...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n bool static cmp(vector<int> a, vector<int> b){\n if(a[0] == b[0]){\n return a[1] < b[1];\n }\n return a[0] > b[0]; \n }\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n int n = people.size();\n sort(pe...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n #define ll long long\n static const bool cmp(vector<int> a,vector<int>b){\n if(a[0]==b[0]){\n return a[1]>b[1];\n }\n return a[0]<b[0];\n }\n\n vector<ll> seg;\n void build(int i,int tl,int tr){\n if(tl==tr){\n seg...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<int>tree;\n void build(int node,int start,int end) {\n if(start==end) {\n tree[node]=1; \n return;\n }\n int mid=(start+end)/2;\n build(2*node,start,mid);\n build(2*node+1,mid+1,end);\n tree[node]=tree[...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n\n class compare{\n\n public:\n\n bool operator()(vector<int> a , vector<int> b){\n\n\n if(a[1] == b[1]){\n return a[0]>b[0];\n }\n\n return a[1]>b[1];\n }\n };\n\n vector<vector<int>> reconstructQueue(...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\nstatic bool cmp(vector<int> a , vector<int> b){\n if(a[0]==b[0])\n return a[1]<b[1];\n return a[0]>b[0];\n}\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n sort(people.begin(),people.end(),cmp);\n vector<vector<int>> ans;\n ...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n static bool cmp(vector<int> a, vector<int> b){\n if(a[0]==b[0]) return a[1]<b[1];\n return a[0]>b[0];\n }\n vector<vector<int>> reconstructQueue(vector<vector<int>>& ppl) {\n sort(ppl.begin(),ppl.end(),cmp);\n int n = ppl.size();\n vec...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n sort(people.begin(), people.end(), [&](vector<int> a, vector<int> b){\n if(a[0] < b[0]) return true;\n else if(a[0] > b[0]) return false;\n else{\n ret...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n sort(people.begin(), people.end(), [&](vector<int> a, vector<int> b){\n if(a[0] > b[0]) return true;\n else if(a[0] < b[0]) return false;\n else{\n ret...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n\n struct myCompare{\n bool operator()(std::vector<int> left, std::vector<int> right){\n if(left[0] == right[0]){return left[1]< right[1];}\n return left[0] > right[0];\n }\n };\n\n vector<vector<int>> reconstructQueue(vector<vector<in...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\n static bool cmp (vector<int>a, vector<int>b){\n if (a[0]==b[0]) return a[1]<b[1];\n return a[0]>b[0];\n }\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n sort(people.begin(),people.end(),cmp);\n vector<vector<int>> res...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n sort(people.begin(),people.end(),[&](const vector<int>a,const vector<int>b)\n {\n if(a[1]==b[1])\n return a[0]<b[0];\n\n return a[1]<b[1];\n });\n\n...
406
<p>You are given an array of people, <code>people</code>, which are the attributes of some people in a queue (not necessarily in order). Each <code>people[i] = [h<sub>i</sub>, k<sub>i</sub>]</code> represents the <code>i<sup>th</sup></code> person of height <code>h<sub>i</sub></code> with <strong>exactly</strong> <code...
3
{ "code": "class Solution {\npublic:\n static bool myComp(vector<int> a, vector<int> b) {\n if(a[0] == b[0]){\n return a[1] < b[1];\n }\n return a[0] > b[0];\n }\n vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {\n sort(people.begin() , people.end(), ...
367
<p>Given a positive integer num, return <code>true</code> <em>if</em> <code>num</code> <em>is a perfect square or</em> <code>false</code> <em>otherwise</em>.</p> <p>A <strong>perfect square</strong> is an integer that is the square of an integer. In other words, it is the product of some integer with itself.</p> <p>Y...
0
{ "code": "class Solution {\npublic:\n bool isPerfectSquare(long long num) {\n long long x;\n if (num==1){return true;}\n for(long long i=1; i<=num/2; i++){\n if((x=i*i)==num){return true;}\n if(x>num){return false;}\n }\nreturn false;}\n};", "memory": "7000" }
367
<p>Given a positive integer num, return <code>true</code> <em>if</em> <code>num</code> <em>is a perfect square or</em> <code>false</code> <em>otherwise</em>.</p> <p>A <strong>perfect square</strong> is an integer that is the square of an integer. In other words, it is the product of some integer with itself.</p> <p>Y...
0
{ "code": "class Solution {\npublic:\n bool isPerfectSquare(int n) {\n int i = 0, j = 0, f = 0;\n int s = 0, e = n/2;\n long long int m = (e-s)/2 + s;\n\n if(n == 1) return true;\n\n while(s <= e){\n long long int b = m * m;\n if(b == n) return true;\n ...
367
<p>Given a positive integer num, return <code>true</code> <em>if</em> <code>num</code> <em>is a perfect square or</em> <code>false</code> <em>otherwise</em>.</p> <p>A <strong>perfect square</strong> is an integer that is the square of an integer. In other words, it is the product of some integer with itself.</p> <p>Y...
0
{ "code": "class Solution {\npublic:\n bool isPerfectSquare(int num) {\n if (num < 0) return false;\n int low = 0, high = num;\n\n while (low <= high) {\n long mid = (high + low) / 2;\n long Square = mid * mid;\n if (Square == num) return true;\n els...
367
<p>Given a positive integer num, return <code>true</code> <em>if</em> <code>num</code> <em>is a perfect square or</em> <code>false</code> <em>otherwise</em>.</p> <p>A <strong>perfect square</strong> is an integer that is the square of an integer. In other words, it is the product of some integer with itself.</p> <p>Y...
0
{ "code": "class Solution {\npublic:double __sqrt(int n)\n{\n double l=0,r=n,ans=n;\n int i=0;\n while(i<100)\n {\n double m=(l+r)/2;\n if(m*m<=n)\n {\n l=m;\n ans=m;\n }\n else r=m;\n i++;\n }\n return ans;\n}\n bool isPerfectSquare...
367
<p>Given a positive integer num, return <code>true</code> <em>if</em> <code>num</code> <em>is a perfect square or</em> <code>false</code> <em>otherwise</em>.</p> <p>A <strong>perfect square</strong> is an integer that is the square of an integer. In other words, it is the product of some integer with itself.</p> <p>Y...
0
{ "code": "class Solution {\npublic:\n bool isPerfectSquare(int num) {\n if(num==1)\n {\n return true;\n }\n for(long long i=2;i<=num/2;i++)\n {\n if(i*i==num)\n {\n return true;\n }\n }\n return false;\n ...
367
<p>Given a positive integer num, return <code>true</code> <em>if</em> <code>num</code> <em>is a perfect square or</em> <code>false</code> <em>otherwise</em>.</p> <p>A <strong>perfect square</strong> is an integer that is the square of an integer. In other words, it is the product of some integer with itself.</p> <p>Y...
0
{ "code": "class Solution {\npublic:\n bool isPerfectSquare(int num) {\n int x =sqrt(num);\n return x*x==num;\n }\n};", "memory": "7300" }
367
<p>Given a positive integer num, return <code>true</code> <em>if</em> <code>num</code> <em>is a perfect square or</em> <code>false</code> <em>otherwise</em>.</p> <p>A <strong>perfect square</strong> is an integer that is the square of an integer. In other words, it is the product of some integer with itself.</p> <p>Y...
0
{ "code": "class Solution {\npublic:\n bool isPerfectSquare(int num) {\n if (num < 1) \n return false;\n\n int low = 1;\n int high = num;\n\n while(high >= low){\n int mid = low + (high-low)/2;\n long long square = static_cast<long long>(mid)*mid;\n ...
1,916
<p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p> <...
0
{ "code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n if(edges[0][0] == edges[1][0] || edges[0][0] == edges[1][1]) return edges[0][0];\n else return edges[0][1]; \n }\n};\n\nint init = [] {\n\tios_base::sync_with_stdio(false);\n\tcin.tie(nullptr);\n\tofstream out(\"...
1,916
<p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p> <...
0
{ "code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int ans;\n if(edges[0][0] == edges[1][0] || edges[0][0] == edges[1][1]){\n ans = edges[0][0];\n } \n\n if(edges[0][1] == edges[1][0] || edges[0][1] == edges[1][1]){\n ans = edg...
1,916
<p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p> <...
0
{ "code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n cout.tie(0);\n cin.tie(0);\n ios_base::sync_with_stdio(0);\n int a = edges[0][0], b = edges[0][1], c = edges[1][0], d = edges[1][1];\n if(a == c || a == d) return a;\n else return b; \n...
1,916
<p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p> <...
0
{ "code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n if(edges[0][0]==edges[1][0]||edges[0][0]==edges[1][1])\n return edges[0][0];\n else\n return edges[0][1];\n }\n};", "memory": "16721" }
1,916
<p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p> <...
0
{ "code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int a = ((edges[0][0]==edges[1][0]) || (edges[0][0]==edges[1][1]))? edges[0][0]:edges[0][1];\n return a;\n }\n};", "memory": "17850" }
1,916
<p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p> <...
0
{ "code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n\n if(edges[0][0] == edges[1][0]|| edges[0][0] == edges[1][1])\n return edges[0][0];\n else\n return edges[0][1];\n \n }\n};", "memory": "18979" }
1,916
<p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p> <...
0
{ "code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n if(edges[0][0]==edges[1][0] || edges[0][0]== edges[1][1]){\n return edges[0][0];\n }\n else{\n return edges[0][1];\n }\n \n }\n};", "memory": "18979" }
1,916
<p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p> <...
0
{ "code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n if(edges[0][0]==edges[1][0] || edges[0][0]==edges[1][1])\n return edges[0][0];\n return edges[0][1];\n }\n};", "memory": "20108" }
1,916
<p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p> <...
0
{ "code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n return edges[0][0] == edges[1][0] || edges[0][0] == edges[1][1] ? edges[0][0] : edges[0][1];\n }\n};", "memory": "20108" }
1,916
<p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p> <...
1
{ "code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int a = edges[0][1];\n int b = edges[0][0];\n if(edges[1][0] ==a || edges[1][1] ==a)\n return a;\n return b;\n\n }\n};", "memory": "21236" }
1,916
<p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p> <...
1
{ "code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edge) {\n // vector<int>first=edge[0];//{a,b}\n // vector<int>second=edge[1];//{c,a} \n // if(first[0]==second[0]|| first[0]==second[1]){\n // return first[0];\n // }\n // return first[1];\n int a=edge[0][...
1,916
<p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p> <...
2
{ "code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n = edges.size() + 1;\n\n vector<bool> visited(n+1,false);\n\n for(int i=0;i<n-1;i++){\n int u = edges[i][0], v = edges[i][1];\n \n if(visited[u]) return u;\n i...
1,916
<p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p> <...
2
{ "code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n bitset<100000> visited=0;\n for(auto& e: edges){\n int v=e[0], w=e[1];\n if (visited[v]) return v;\n if (visited[w]) return w;\n visited[v]=visited[w]=1;\n }\n ...
1,916
<p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p> <...
2
{ "code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n = edges.size();\n vector<int> degree(n +2 , 0); \n\n for (auto &edge : edges) {\n degree[edge[0]]++;\n degree[edge[1]]++;\n\n \n if (degree[edge[0]] == n) ret...
1,916
<p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p> <...
2
{ "code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n // Initialize a vector to count degrees of each node\n // Use maximum possible size based on edge counts\n vector<int> count(edges.size() + 2, 0);\n \n // Count the degree of each node\n ...
1,916
<p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p> <...
2
{ "code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges)\n {\n vector<int> cnt(edges.size()+2, 0);\n for (int i = 0; i < edges.size()-1; i++)\n {\n if (edges[i][0] == edges[i+1][0] || edges[i][0] == edges[i+1][1]) return edges[i][0];\n if (edge...