id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n set<int> s;\n for(int i:nums){\n s.insert(i);\n }\n return !(nums.size()==s.size());\n }\n};", "memory": "75790" }
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n set<int> s;\n int n = nums.size();\n for (int i = 0; i < n; i++) {\n s.insert(nums[i]);\n }\n return (s.size() != n);\n }\n};", "memory": "75996" }
217
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <div class="example-block"> <p><strong>Input:</stron...
3
{ "code": "class Solution {\npublic:\n bool containsDuplicate(vector<int>& nums) {\n \n // sort(nums.begin(),nums.end());\n\n // int n = nums.size();\n\n // for(int i=0;i<n-1;i++)\n // if(nums[i] == nums[i+1])\n // return true;\n\n // return false;\n\n ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n // the intuition is to start from left-most point, then search all the\n // coordinates of the buildings to determine the next left-most point;\n // for each point, determine the height of...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n vector<vector<int>> v;\n\n if (buildings.empty()) return v;\n\n vector<int> m;\n int currX = -1;\n int currY = 0;\n // m.push_back(currX);\n // m.push_back(curr...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n priority_queue<pair<int,int>> pq;\n vector<vector<int>> ans;\n for(int i=0;i<buildings.size();i++){\n while(!pq.empty() and pq.top().second<buildings[i][0]){\n in...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n vector<vector<int>> res;\n vector<vector<int>> lines;\n for (const vector<int>& b : buildings) {\n lines.push_back({b[0], b[2], 0});\n lines.push_back({b[1], b[2], 1}...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n map<int, vector<int>> line; \n map<int, int> vis; \n for (auto &a : buildings) {\n line[a[0]].push_back(a[2]);\n line[a[1]].push_back(-a[2]);\n }\n pr...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n /*\n key points: things start and end\n max_heap: heights of all the buildings\n */\n unordered_set<int> currentBuildings;\n map<int, vector<int>> xToBuilding;\n ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n int n=buildings.size(),i,j,ch=0;\n vector<vector<int>> ans;\n multiset<int> heights;\n map<int,vector<int>> cordinates;\n for(int i=0;i<n;i++){\n int left=building...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\n\npublic:\n\n vector<vector<int>> getSkyline(vector<vector<int>>& ar) {\n\n vector<pair<int,int>> v;\n\n for(auto it:ar){\n\n int l=it[0],r=it[1],h=it[2];\n\n v.emplace_back(l,-h);\n\n v.emplace_back(r,h);\n\n }\n\n sort(v.be...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\nvector<vector<int>> getSkyline (vector<vector<int>>& buildings) {\n std::map<int, vector<pair<int, bool>> > mp; \n std::multiset<int> ms;\n std::vector<vector<int>> ans;\n\n for (auto i : buildings) {\n mp[i[0]].push_back(make_pair(i[2], true));\n mp[i[1...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n vector<vector<int>>v;\n multiset<int>pq;\n pq.insert(0);\n for(auto x : buildings){\n v.push_back({x[0],-x[2]});\n v.push_back({x[1],x[2]});\n }\n ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n vector<vector<int>> p; // points\n vector<vector<int>> ans;\n for (auto x : buildings) {\n p.push_back({x[0], x[2], 1});\n p.push_back({x[1], x[2], 0});\n }\n ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "#define vi vector <int>\nclass Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& b) {\n vector<vi> p, ans;\n for(auto it : b){\n p.push_back({it[0],it[2],1});\n p.push_back({it[1],it[2],0});\n }\n sort(p.begin(), p.end());\n ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n multiset<vector<int>> s;\n vector<vector<int>> ans;\n for(auto building: buildings){\n s.insert({building[0], building[2], 0});\n s.insert({building[1], building[2], ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n void update(vector<int>& tree,int n,int pos,int val){\n pos+=n;\n tree[pos]=val;\n pos/=2;\n while(pos){\n tree[pos]=max(tree[pos*2],tree[pos*2+1]);\n pos/=2;\n }\n }\n int querry(vector<int>& tree){\n retu...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& v) \n {\n int n = v.size();\n map<int, multiset<pair<int,int>> > mp;\n for (auto x : v)\n {\n mp[x[0]].insert({1,x[2]});\n mp[x[1]].insert({2,x[2]});\n }\n m...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "\nclass Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n multiset<vector<int>>diffA;\n for(auto it : buildings){\n diffA.insert({it[0],it[2],1});\n diffA.insert({it[1],it[2],-1});\n }\n multiset<int>maxHeight;\n ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n vector<vector<int>>edges;\n vector<vector<int>>ans;\n priority_queue<vector<int>>pq;\n map<int,int>mp;\n for(int i=0;i<buildings.size();i++){\n edges.push_back({bu...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n int n = buildings.size();\n\n vector<vector<int>> edges;\n vector<vector<int>> ans;\n int heights[n];\n\n map<int, int> mp;\n for(int i = 0; i < n; i++){\n ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n map<int,vector<vector<int>> > m ;// maps the x coordinates to points. 0->start, 1 ->end\n int i,j,n = buildings.size();\n for(i=0;i<n;i++){\n m[buildings[i][0]].push_back({i,...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n map<int,vector<vector<int>> > m ;// maps the x coordinates to points. 0->start, 1 ->end\n int i,j,n = buildings.size();\n for(i=0;i<n;i++){\n m[buildings[i][0]].push_back({i,...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Compare {\npublic:\n bool operator()(const vector<int>& a, const vector<int>& b) const {\n if (a[0] != b[0]) return a[0] > b[0]; // Sort by x-coordinate (ascending)\n return a[1] > b[1]; // Sort by height (ascending for ties)\n }\n};\n\nvoid printPriorityQueue(priority_queue<vecto...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n int n = buildings.size();\n \n \n unordered_map<int, vector<vector<int>>> hash;\n for(int i=0;i<n;i++) {\n hash[buildings[i][0]].push_back({0, i});\n ha...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Compare {\npublic:\n bool operator()(const vector<int>& a, const vector<int>& b) const {\n if (a[0] != b[0]) return a[0] > b[0]; // Sort by x-coordinate (ascending)\n return a[1] > b[1]; // Sort by height (ascending for ties)\n }\n};\n\nvoid printPriorityQueue(priority_queue<vecto...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n struct tree {\n int l, r;\n int tag, val;\n } cnt[400004];\n void Tree(int k, int l, int r) {\n cnt[k].l = l, cnt[k].r = r;\n int mid = (l + r) / 2;\n cnt[k].tag = 0;\n cnt[k].val = 0;\n if (l != r) {\n Tree(2 ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n unordered_set<int> ust;\n vector<int> nums;\n unordered_map<int, unordered_map<int, int>> toAdd;\n unordered_map<int, unordered_map<int, int>> toRemove;\n unordered_map<int, ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class SegTreeNode\n{\n public:\n SegTreeNode* left = NULL;\n SegTreeNode* right = NULL;\n int start, end;\n int info; // the maximum value of the range\n bool tag; \n \n SegTreeNode(int a, int b, int val) { // init for range [a,b] with val \n tag = 0;\n ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Node\n{\n public:\n long long int l, r, m, val;\n Node *left, *right;\n\n Node(long long int x, long long int y, long long int v)\n {\n l=x;\n r=y;\n m=l+(r-l)/2;\n val=v;\n left=right=nullptr;\n }\n\n};\n\nclass Solution {\n Node *root;\n vo...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n unordered_set<int> ust;\n vector<int> nums;\n unordered_map<int, unordered_map<int, int>> toAdd;\n unordered_map<int, unordered_map<int, int>> toRemove;\n unordered_map<int, ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "using pii = pair<int, int>; \nclass Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n int maxX=0, currHeight = 0;\n unordered_map<int, unordered_set<int>> starting;\n unordered_map<int, unordered_set<int>> ending;\n set<int> coords;\n ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n int maxX=0, currHeight = 0;\n unordered_map<int, unordered_set<int>> starting;\n unordered_map<int, unordered_set<int>> ending;\n set<int> coords;\n map<int, unordered_set<in...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "using pii = pair<int, int>; \nclass Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n // sort(buildings.begin(), buildings.end());\n int maxX=0, currHeight = 0;\n unordered_map<int, unordered_set<int>> starting;\n unordered_map<int, unor...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n int N = 40001;\n\n // start, end => start and end of range that needs to be modified\n void ss(vector<int> &tree,int node,int l, int r, int start, int end, int val) {\n int mid = (l + r)/2;\n if(l > r || start > r || end < l) return;\n // cout << no...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n if (buildings.empty()) return {};\n \n Skyline result = mergeSortSkylines(buildings, 0, buildings.size() - 1);\n \n // Convert Skyline (vector<pair<int, int>>) to vector<vect...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n if (buildings.empty()) return {};\n \n Skyline result = mergeSortSkylines(buildings, 0, buildings.size() - 1);\n \n // Convert Skyline (vector<pair<int, int>>) to vector<vect...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n class Compare {\n public:\n bool operator()(const vector<int> l, const vector<int> r) const {\n if (l[2] == r[2])\n return l[1] < r[1];\n ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "auto hcmp = [](const vector<int>& a, const vector<int> b) {\n return a[1] < b[1];\n};\n\nbool pcmp (const vector<int>& a, const vector<int> b) {\n if ( a[0] == b[0]) {\n return a[2] > b[2];\n } else {\n return a[0] < b[0];\n }\n};\n\nclass Solution {\npublic:\n vector<vector<in...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n bool sortcol(const vector<int>& v1, const vector<int>& v2) {\n return v1[2] > v2[2];\n }\n vector<vector<int>> find_sky(vector<vector<int>>& buildings) {\n vector<vector<int>> values;\n map<int, int> val;\n set<int> unique_nos;\n int i...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n bool sortcol(const vector<int>& v1, const vector<int>& v2) {\n return v1[2] > v2[2];\n }\n vector<vector<int>> find_sky(vector<vector<int>>& buildings) {\n vector<vector<int>> values;\n map<int, int> val;\n set<int> unique_nos;\n int i...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n bool sortcol(const vector<int>& v1, const vector<int>& v2) {\n return v1[2] > v2[2];\n }\n vector<vector<int>> find_sky(vector<vector<int>>& buildings) {\n vector<vector<int>> values;\n map<int, int> val;\n set<int> unique_nos;\n int i...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n bool sortcol(const vector<int>& v1, const vector<int>& v2) {\n return v1[2] > v2[2];\n }\n vector<vector<int>> find_sky(vector<vector<int>>& buildings) {\n vector<vector<int>> values;\n map<int, int> val;\n set<int> unique_nos;\n int i...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n bool sortcol(const vector<int>& v1, const vector<int>& v2) {\n return v1[2] > v2[2];\n }\n vector<vector<int>> find_sky(vector<vector<int>>& buildings) {\n vector<vector<int>> values;\n map<int, int> val;\n set<int> unique_nos;\n int i...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "/* Scanline: \n### Detailed Walkthrough of the Implementation\n- **Data Structures**:\n - A `map<int, vector<pair<int,bool>>>` named `mp` is used to store building events, where each key represents a position (either the start or end of a building) and the value is a vector of pairs. Each pair contains th...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "struct compare{\n bool operator()(vector<int> lhs, vector<int> rhs) {\n if (lhs[2] < rhs[2])\n return true;\n return false;\n }\n};\n\nclass Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n sort(buildings.begin(), buildings.en...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n return divideAndConquer(buildings, 0, buildings.size() - 1);\n }\n\nprivate:\n vector<vector<int>> divideAndConquer(const vector<vector<int>>& buildings, int left, int right) {\n if...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n return divideAndConquer(buildings, 0, buildings.size() - 1);\n }\n\nprivate:\n vector<vector<int>> divideAndConquer(vector<vector<int>>& buildings, int left, int right) {\n if (left > right...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "using vv = vector<vector<int>>;\n\nclass Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n\n return divide(buildings, 0, buildings.size()-1);\n \n }\n\n vv divide(vv& buildings, int left, int right)\n {\n if(left == right)\n {\n...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\nprivate:\n void printvec(vector<vector<int>>& vec) {\n cout << '[';\n for (auto& v: vec) {\n cout << '(' << v[0] << ',' << v[1] << \"),\";\n }\n cout << ']' << endl;\n }\n\n vector<vector<int>> helper(vector<vector<int>>& buildings, int i, i...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "bool cmpHeight(const vector<int>& l, const vector<int>& r) {\n return l[0] < r[0];\n}\nclass Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n return buildSkyLine(buildings, 0, buildings.size()-1);\n }\nprivate:\n vector<vector<int>> buildSkyLine(co...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n int n = buildings.size();\n if (n == 0) return {};\n\n return divideAndConquer(buildings, 0, n - 1);\n }\n\nprivate:\n vector<vector<int>> divideAndConquer(vector<vector<int>>& build...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n int n = buildings.size();\n int m = prepare(buildings, n);\n \n priority_queue<pair<int, int>> heap;\n vector<int> height(m + 1, 0);\n\n for (int i = 1, j = 0; i <= m;...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n return DAndC(0, buildings.size() - 1, buildings);\n }\n\nprivate:\n vector<vector<int>> DAndC(int left, int right, const vector<vector<int>>& buildings) {\n if (left == right)\n ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n return DAndC(0, buildings.size() - 1, buildings);\n }\n\nprivate:\n vector<vector<int>> DAndC(int left, int right, const vector<vector<int>>& buildings) {\n if (left == right)\n ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n return DAndC(0, buildings.size() - 1, buildings);\n }\n\nprivate:\n vector<vector<int>> DAndC(int left, int right, const vector<vector<int>>& buildings) {\n if (left == right)\n ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n return DAndC(0, buildings.size() - 1, buildings);\n }\n\nprivate:\n vector<vector<int>> DAndC(int left, int right, const vector<vector<int>>& buildings) {\n if (left == right)\n ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n return DAndC(0, buildings.size() - 1, buildings);\n }\n\nprivate:\n vector<vector<int>> DAndC(int left, int right, const vector<vector<int>>& buildings) {\n if (left == right)\n ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n static bool compre(vector<int> a,vector<int> b) {\n if(a[0]<b[0])\n return true;\n if(a[0]>b[0])\n return false;\n if(a[1]<b[1])\n return true;\n if(a[1]>b[1])\n return false;\n if(a[2]<b[2])\n return true;...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n vector<vector<int>>ans;\n\n\n vector<vector<int>>arr;\n\n for(int i=0;i<buildings.size();i++)\n {\n int l=buildings[i][0];\n int r=buildings[i][1];\n ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class Solution {\npublic:\n static bool compre(vector<int> a,vector<int> b) {\n if(a[0]<b[0])\n return true;\n if(a[0]>b[0])\n return false;\n if(a[1]<b[1])\n return true;\n if(a[1]>b[1])\n return false;\n if(a[2]<b[2])\n return true;...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "\nclass Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& bud) {\n \n vector<int> lines, h;\n vector<vector<int>> info; // boundary, h, build idx\n\n for(int i=0; i<bud.size(); i++){\n info.push_back({bud[i][0], bud[i][2], i});\n ...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "bool compare(vector<int>a,vector<int>b){\n if(a[0]!=b[0]){\n return a[0]<b[0];\n }\n if(a[1]!=b[1]){\n return a[1]>b[1];\n }\n if(a[1]==1){\n return a[2]>b[2];\n }else{\n return a[2]<b[2];\n }\n}\n\nclass Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& build...
218
<p>A city&#39;s <strong>skyline</strong> is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return <em>the <strong>skyline</strong> formed by these buildings collectively</em>.</p> <p>The geometric informati...
3
{ "code": "class comp{\n public:\n bool operator()(vector<int>pA, vector<int>pB){\n if(pA[0] == pB[0]){\n if(pA[1]==pB[1]){\n if(pA[1]==1) return pA[2]<pB[2];\n else return pA[2]>pB[2];\n }\n else return pA[1]<pB[1];\n }\n retur...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n for(int i=0;i<nums.size();i++){\n for(int j=i+1; j<nums.size() && j<=i+k; j++){\n if(nums[i]==nums[j] && (i-j)<=k) return true;\n }\n }\n ...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n int n = nums.size();\n if (n <= 1) {\n return false;\n }\n \n for (int i = 0; i < n; i++) {\n int c = nums[i];\n\n for (int j = i + 1; j < n && j <= ...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n constexpr int HashBits = 9;\n constexpr int HashSize = 1 << HashBits;\n constexpr int HashMask = (1 << HashBits) - 1;\n array<int, HashSize> table;\n table.fill(-1);\n for (in...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n constexpr int HashBits = 10;\n constexpr int HashSize = 1 << HashBits;\n constexpr int HashMask = (1 << HashBits) - 1;\n array<int, HashSize> table;\n table.fill(-(k+1));\n fo...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n const size_t n = nums.size();\n const int HashBits = log2(n) + 3;\n const int HashSize = 1 << HashBits;\n const int HashMask = (1 << HashBits) - 1;\n vector<bool> bloom(HashSize, fal...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n // unordered_map<int,int> hm;\n // for(int i=0;i<nums.size();i++){\n // if(hm.count(nums[i]) && abs(hm[nums[i]]-i)<=k){\n // return true;\n // }\n // hm[nu...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n /* for(int i=0; i <nums.size(); i++){\n for(int j=i+1; j <= i+k && j < nums.size(); j++){\n if (nums[i] == nums[j]){\n return true;\n }\n }...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n //make a map of element -> index\n // map size == k\nbool containsNearbyDuplicate(vector<int>& nums, int k) {\n int n=nums.size();\n pair<int,int> p[n];\n for(int i=0;i<n;i++) {\n p[i] = {nums[i],i};\n }\n sort(p,p+n);\n ...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n pair<int,int> arr[nums.size()];\n for(int i=0;i<nums.size();i++){\n arr[i]={nums[i],i};\n }\n sort(arr,arr+nums.size());\n for(int i=0;i<nums.size()-1;i++){\n i...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n vector<int> iarray(nums.size());\n\n iota(begin(iarray), end(iarray), 0);\n\n sort(iarray.begin(), iarray.end(),\n [&](const auto& x, const auto& y){\n return nums[x] < ...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n vector<int> iarray(nums.size());\n\n iota(begin(iarray), end(iarray), 0);\n\n sort(iarray.begin(), iarray.end(),\n [&](const auto& x, const auto& y){\n return nums[x] < ...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n int n=nums.size();\n std::pair<int,size_t> p[n];\n for(size_t i = 0; i < n; i++) \n p[i] = { nums[i], i };\n \n std::sort(p,p+n);\n for(size_t i = 1; i < n; i++) {\...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n std::vector<int> memo;\n for (int i = 0; i < nums.size(); i++) {\n int n = nums[i];\n int s_idx = std::max(0, i - k);\n if (std::find(memo.begin() + s_idx, memo.end(), n)...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "//using hashtable O(n)->space , O()\nclass Solution1 {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n int n=nums.size();\n pair<int,int> p[n];\n for(int i=0;i<n;i++) {\n p[i] = {nums[i],i};\n }\n sort(p,p+n);\n for(int i=1;i<n;i...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "//using hashtable O(n)->space , O()\nclass Solution1 {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n int n=nums.size();\n pair<int,int> p[n];\n for(int i=0;i<n;i++) {\n p[i] = {nums[i],i};\n }\n sort(p,p+n);\n for(int i=1;i<n;i...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n int N = (int)nums.size();\n vector<int> ids(N);\n for(int i = 0; i < N; i++) {\n ids[i] = i;\n }\n sort(ids.begin(), ids.end(), [&nums](int a, int b) {\n if(num...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n int N = (int)nums.size();\n vector<int> ids(N);\n for(int i = 0; i < N; i++) {\n ids[i] = i;\n }\n sort(ids.begin(), ids.end(), [&nums](int a, int b) {\n return...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n \n // int i=0;\n // while(i<k) i++;\n // if( nums.size()<=k) return false;\n set<int> x;\n for(int i=0; i<k && i<nums.size(); i++)\n x.insert(nums[i]);\n\n if(x.size()==nums....
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n \n // int i=0;\n // while(i<k) i++;\n // if( nums.size()<=k) return false;\n set<int> x;\n for(int i=0; i<k && i<nums.size(); i++)\n x.insert(nums[i]);\n\n if(x.size()==nums....
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n \n int sz = nums.size();\n vector<int>idx(sz, 0);\n\n bool f_possible = false;\n\n for(int i = 0;i < sz;i++)\n {\n idx[i] = i;\n }\n\n stable_sort(idx...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n const size_t n = nums.size();\n const int HashBits = log2(n + n/2);\n const int HashSize = 1 << HashBits;\n const int HashMask = (1 << HashBits) - 1;\n vector<int> table(HashSize, -(...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n vector<int> a = nums;\n sort(a.begin(),a.end());\n int lap = a[0];\n vector<int> trungs;\n bool nhap = false;\n for(int i = 1; i < a.size();i++)\n {\n if(a[i...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n std::vector<std::pair<int, int>> cache(nums.size());\n for(int i{0}; const int num : nums) {\n cache[i] = {num, i};\n ++i;\n }\n std::sort(cache.begin(), cache.end());...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n Solution() {\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(0);\n }\n\n bool containsNearbyDuplicate(const std::vector<int>& nums, const int k) const {\n std::vector<std::pair<int, int>> cache(nums.size());\n for(int i{0}; const int ...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n int n = nums.size();\n vector<pair<int, int>> listNum(n);\n for (int i = 0; i < n; i++)\n {\n listNum[i].first = nums[i];\n listNum[i].second = i;\n }\n ...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "static const auto speedup = []() {\n std::ios::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n std::vector<std::pair<int, int>> nums2idx(nums.size());...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n const size_t n = nums.size();\n const int HashBits = log2(n) + 1;\n const int HashSize = 1 << HashBits;\n const int HashMask = (1 << HashBits) - 1;\n vector<int> table(HashSize, -(k+...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n const size_t n = nums.size();\n const int HashBits = log2(n) + 1;\n const int HashSize = 1 << HashBits;\n const int HashMask = (1 << HashBits) - 1;\n vector<int> table(HashSize, -(k+...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n std::vector<std::pair<int, int>> nums_idx(nums.size());\n for (int i = 0; i < nums.size(); ++i) {\n nums_idx[i] = {nums[i], i};\n }\n std::stable_sort(nums_idx.begin(), nums_idx....
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n //int* p=nums;\n //int* q=nums+nums.size();\n vector<int> nums2;\n for(int i=0;i<nums.size();i++){\n nums2.push_back(nums.at(i));\n }\n int c=0;\n sort(nums2...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n\n static bool compare(pair<int, int> a, pair<int, int>b){\n return a.first < b.first;\n }\n\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n vector<pair<int, int>>pairs;\n for(int i = 0; i < nums.size(); i++){\n pairs.push_bac...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n unordered_set<int>window;\n int n=nums.size();\n for(int i=0;i<n;i++){\n if(window.find(nums[i])!=window.end()){\n return true;\n }\n window.insert(...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n std::unordered_set<int> hash;\n hash.reserve(k);\n\n for (size_t i = 0; i < nums.size(); ++i) {\n auto it = hash.find(nums[i]);\n if (it != hash.end()) {\n ret...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n int n=nums.size();\n vector<pair<int,int>> ans;\n for(int i=0; i<n; i++){\n ans.push_back({nums[i],i});\n } \n sort(ans.begin(), ans.end());\n for(int i=0; i<n-1; i...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n vector<pair<int, int>> arr;\n for (int i = 0; i < nums.size(); i++) {\n arr.push_back(make_pair(nums[i], i));\n }\n sort(arr.begin(), arr.end());\n for (int i = 0; i < arr...
219
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p> <p...
0
{ "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n vector<pair<int, int>> arr;\n for (int i = 0; i < nums.size(); i++) {\n arr.push_back(make_pair(nums[i], i));\n ...