id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n std::vector<int> restoreArray(const std::vector<...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n std::vector<int> restoreArray(const std::vector<...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n std::vector<int> restoreArray(const std::vector<...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n std::vector<int> restoreArray(const std::vector<...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n std::vector<int> restoreArray(const std::vector<...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n std::vector<int> restoreArray(const std::vector<...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n int n = adjacentPairs.size() + 1;\n unordered_map<int, vector<int>> g;\n for (auto& e : adjacentPairs) {\n int a = e[0], b = e[1];\n g[a].push_back(b);\n g[b...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n unordered_map<int,vector<int>>mp;\n for(auto c:adjacentPairs){\n mp[c[0]].push_back(c[1]);\n mp[c[1]].push_back(c[0]);\n }\n int start=0;\n for(auto c:mp)...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n int n = adjacentPairs.size() + 1;\n vector<int> ans;\n unordered_map<int, vector<int>> adj;\n\n for(auto edge : adjacentPairs){\n adj[edge[0]].push_back(edge[1]);\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& pairs) {\n unordered_map<int,vector<int>> adj;\n for(auto ele:pairs){\n adj[ele[0]].push_back(ele[1]);\n adj[ele[1]].push_back(ele[0]);\n };\n vector<int> res;\n for(auto el...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n unordered_map<int,vector<int>> graph;\n for(const auto it: adjacentPairs){\n graph[it[0]].push_back(it[1]);\n graph[it[1]].push_back(it[0]);\n }\n vector<int>ans...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n int n = adjacentPairs.size()+1;\n\n unordered_map<int, vector<int>>graph;\n \n for(auto it: adjacentPairs)\n {\n graph[it[0]].push_back(it[1]);\n graph[it...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n map<int,vector<int>> m;\n for(int i=0;i<adjacentPairs.size();i++){\n int a = adjacentPairs[i][0];\n int b = adjacentPairs[i][1];\n m[a].push_back(b);\n m...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n \n unordered_map<int,vector<int>>map;\n\n for(auto p : adjacentPairs){\n map[p[0]].push_back(p[1]);\n map[p[1]].push_back(p[0]);\n }\n\n int source;\n\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n int n = adjacentPairs.size()+1;\n vector<int> nums (n);\n\n map<int, vector<int>> adj;\n\n for(auto pair : adjacentPairs)\n {\n adj[pair.at(0)].push_back(pair.at(1))...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n // Step 1: Build adjacency list (undirected graph)\n unordered_map<int, vector<int>> adj;\n for (const auto& pair : adjacentPairs) {\n adj[pair[0]].push_back(pair[1]);\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n unordered_map<int,vector<int>> store;\n unordered_map<int,int> track;\n for(auto &pair:adjacentPairs){\n store[pair[0]].push_back(pair[1]);\n store[pair[1]].push_back(p...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n#define nline '\\n'\n#define sp ' '\n#define all(x) x.begin(), x.end()\n#define rall(x) x.rbegin(), x.rend()\nstatic int fastIO = []\n{\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n return 0;\n}();\n\nclass Solution\n{\npublic...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n int n=adjacentPairs.size()+1;\n vector<int>ans;\n unordered_map<int,vector<int>>adj;\n unordered_map<int, int> indegree;\n for(int i=0;i<adjacentPairs.size();i++)\n {\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
0
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n int n = adjacentPairs.size() + 1;\n // build the graph\n unordered_map<int, vector<int>> graph;\n unordered_map<int, int> indegree;\n for (auto& pair : adjacentPairs) {\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n // Construct an adjacency list from the edge list\n\n // Keys: elements in our list\n // Values: adjacent elements to the current elment in original list\n // Note: edges are undirect...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n int n=adjacentPairs.size()+1;\n unordered_map<int,vector<int>>mp;\n for(int i=0;i<adjacentPairs.size();i++){\n mp[adjacentPairs[i][0]].push_back(adjacentPairs[i][1]);\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n unordered_map<int,vector<int>> mp;\n for(auto elem:adjacentPairs){\n if(mp.find(elem[0]) == mp.end()){\n mp[elem[0]] = vector<int>();\n }\n mp[elem[0...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "\nclass Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n map<int,vector<int>> adjMap;\n for(auto&pair : adjacentPairs){\n adjMap[pair[0]].push_back(pair[1]);\n adjMap[pair[1]].push_back(pair[0]);\n }\n vector<int> re...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n unordered_map<int,vector<int>>adj;\n vector<int>ans;\n\n for(auto i:adjacentPairs){\n adj[i[0]].push_back(i[1]);\n adj[i[1]].push_back(i[0]);\n }\n\n for(...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "\nclass Solution {\npublic:\n void bfs(int start, map<int, vector<int>>& adjMap, vector<int>& result) {\n queue<int> q;\n map<int, bool> visited;\n q.push(start);\n visited[start] = true;\n while (!q.empty()) {\n int current = q.front();\n q.pop()...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n std::vector<int> restoreArray(const std::vector<...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n std::vector<int> restoreArray(const std::vector<...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n int n=adjacentPairs.size();\n map<int,vector<int>> mp;\n map<int,int> vis;\n for(int i=0;i<n;i++){\n mp[adjacentPairs[i][0]].push_back(adjacentPairs[i][1]);\n mp...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n\n map<int,vector<int>>mp;\n\n int src = 0;\n\n for(auto edge: adjacentPairs){\n int x = edge[0];\n int y = edge[1];\n\n mp[x].push_back(y);\n mp[y...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& a) {\n map<int,set<int>> mp;\n for(int i=0;i<a.size();i++){\n mp[a[i][0]].insert(i);\n mp[a[i][1]].insert(i); \n }\n int start=0;\n int id=0;\n for(int i=0;i<a.size(...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n map<int,set<int>> m;\n for(auto& p:adjacentPairs){\n m[p[0]].insert(p[1]);\n m[p[1]].insert(p[0]);\n }\n int head;\n for(auto & item:m){\n if(i...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n unordered_map<int,vector<int>>adj;\n int n = adjacentPairs.size();\n //creating adjacency list\n for(auto x:adjacentPairs){\n int u = x[0] , v = x[1];\n adj[u].p...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& v) {\n unordered_map<int, vector<int>> mp;\n for(auto e: v){\n mp[e[0]].push_back(e[1]);\n mp[e[1]].push_back(e[0]);\n }\n\n int start;\n for(auto entry : mp){\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n int n = adjacentPairs.size()+1;\n vector<int> ans(n);\n map<int, vector<int>> map1;\n for(int i=0;i<adjacentPairs.size();i++){\n map1[adjacentPairs[i][0]].push_back(adjacen...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n if(adjacentPairs.size()==1){\n return {adjacentPairs[0][0],adjacentPairs[0][1]};\n }\n unordered_map<int,vector<int>> um;\n for(auto it:adjacentPairs){\n int u=i...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adj) {\n map<int,vector<int>> graph;\n map<int,int> indegree;\n int n=adj.size()+1;\n for(auto v:adj)\n {\n graph[v[0]].push_back(v[1]);\n graph[v[1]].push_back(v[0]);\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "class Solution {\nprivate:\n typedef map<int, vector<int>> GRAPH;\n GRAPH res;\n\n void addEdge(GRAPH &graph, int u, int v) {\n graph[u].push_back(v);\n graph[v].push_back(u);\n }\n\npublic:\n vector<int> restoreArray(vector<vector<int>> &adjacentPairs) {\n vector<int> r...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "#pragma GCC optimize(\"O3\")\nclass Solution {\npublic:\n unordered_map<int, vector<int>> adj;\n void build_adj(vector<vector<int>>& adjacentPairs){\n #pragma unroll\n for(auto& e: adjacentPairs){\n int v0=e[0], v1=e[1];\n if (adj.count(v0)) adj[v0].push_back(v1);\...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "#pragma GCC optimize(\"O3\")\nclass Solution {\npublic:\n unordered_map<int, vector<int>> adj;\n void build_adj(vector<vector<int>>& adjacentPairs){\n #pragma unroll\n for(auto& e: adjacentPairs){\n int v0=e[0], v1=e[1];\n if (adj.count(v0)) adj[v0].push_back(v1);\...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "class Solution {\npublic:\n void dfs(int src, int prev, vector<int>& ans, unordered_map<int,vector<int>>& adj) {\n ans.push_back(src);\n for(const int& adjNode : adj[src]) {\n if(adjNode != prev) {\n dfs(adjNode,src,ans,adj);\n }\n }\n }\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
1
{ "code": "class Solution {\npublic:\n void dfs(int src, int prev, vector<int>& ans, unordered_map<int,vector<int>>& adj) {\n ans.push_back(src);\n for(const int& adjNode : adj[src]) {\n if(adjNode != prev) {\n dfs(adjNode,src,ans,adj);\n }\n }\n }\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n map<int, vector<int>> adjlist;\n for(auto x:adjacentPairs){\n adjlist[x[0]].push_back(x[1]);\n adjlist[x[1]].push_back(x[0]);\n }\n vector<int> res;\n set...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution {\npublic:\n void dfs(vector<int>&res,map<int,pair<vector<int>,bool>>&m1,int item){\n\tm1[item].second=true;\n\tres.push_back(item);\n\tfor(int i=0; i<m1[item].first.size(); i++){\n\t\tint key=m1[item].first[i];\n\t\tif(!m1[key].second){\n\t\t\tdfs(res,m1,key);\n\t\t}\n\t}\n}\nvector<int> ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution {\npublic:\n vector<int> order;\n void dfs(int v,int p,map<int,vector<int>> &adj)\n {\n for(auto u : adj[v])\n {\n if(u==p) continue;\n dfs(u,v,adj);\n }\n order.push_back(v);\n }\n vector<int> restoreArray(vector<vector<int>>&...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& a) {\n unordered_map<int,vector<int>>mp;\n for(auto x:a){\n mp[x[0]].push_back(x[1]);\n mp[x[1]].push_back(x[0]);\n }\n int st=INT_MIN;\n for(auto x:mp){\n //cout...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "\nclass Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& arr) {\n map<int, int> mp;\n for (const auto& pair : arr) {\n mp[pair[0]]++;\n mp[pair[1]]++;\n }\n\n int start = 0;\n for (const auto& entry : mp) {\n if (entr...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& a) {\n int i,j,k,p,q,n=a.size();\n map<int,vector<int>> m;\n map<int,int> mp,m1;\n for(i=0;i<n;i++){\n for(j=0;j<2;j++){\n mp[a[i][j]]++;\n }\n m[a[i][0]]...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n vector<int> ans;\n unordered_map<int,vector<int>> mp;\n for(auto it: adjacentPairs){\n mp[it[0]].push_back(it[1]);\n mp[it[1]].push_back(it[0]);\n }\n set...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n // [num] -> [neighbors] (one or two elements only)\n // find me one of them that has only 1 neighbor\n // set of already used unique numbers\n // build the array as you go\n un...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n map<int,vector<int>> m;\n for(int i=0;i<adjacentPairs.size(); i++) {\n m[adjacentPairs[i][0]].push_back(adjacentPairs[i][1]);\n m[adjacentPairs[i][1]].push_back(adjacentPairs[...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "#include <vector>\n#include <unordered_map>\n#include <set>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n unordered_map<int, set<int>> adj;\n for (auto& pair : adjacentPairs) {\n adj[pair[0]].insert(pair[1])...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& pairs) {\n unordered_map<int,int> mp;\n unordered_map<int,int> vis;\n unordered_map<int, vector<int>> bagal;\n \n for(auto x:pairs)\n {\n mp[x[0]]++;\n mp[x[1]]++;\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& pairs) {\n unordered_map<int,int> mp;\n unordered_map<int,int> vis;\n unordered_map<int, vector<int>> bagal;\n \n for(auto x:pairs)\n {\n mp[x[0]]++;\n mp[x[1]]++;\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution {\nprivate:\nvoid dfs(int u,int prev,unordered_map<int,vector<int>>&mp,vector<int>&res)\n{\n res.push_back(u);\n for(int v:mp[u])\n {\n if(v!=prev)\n dfs(v,u,mp,res);\n }\n}\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) \n {\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution {\npublic:\n void dfs(int node,vector<int>& ans,int prev,unordered_map<int,vector<int>>&mp){\n ans.push_back(node);\n for(auto it:mp[node]){\n if(it!=prev){\n dfs(it,ans,node,mp);\n }\n }\n }\n vector<int> restoreArray(vector...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution {\npublic:\n vector<int>ans;\n void dfs(int start, int prev, unordered_map<int, vector<int>> &adj){\n ans.push_back(start);\n for(auto v:adj[start]){\n if(v!=prev) dfs(v, start,adj);\n }\n }\n vector<int> restoreArray(vector<vector<int>>& adjacentP...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution {\npublic:\n void dfs(int node, unordered_map<int, vector<int>>& adj, vector<int>& ans, unordered_map<int,bool>& vis) {\n vis[node]=1;\n ans.push_back(node);\n \n for (auto& neighbor : adj[node]) {\n if (vis.find(neighbor) == vis.end()) {\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution {\npublic:\n inline vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n unordered_map<int, vector<int>> graph;\n map<int, bool> visited;\n map<int, int> edgeCount;\n\n for (auto p : adjacentPairs) {\n edgeCount[p[0]]++; edgeCount[p[1]]++...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution\n{\n public:\n vector<int> restoreArray(vector<vector < int>> &adjacentPairs)\n {\n map<int, vector < int>> adj;\n map<int, int> indegree;\n for (auto it: adjacentPairs)\n {\n adj[it[0]].push_back(it[1]);\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution\n{\n public:\n vector<int> restoreArray(vector<vector < int>> &adjacentPairs)\n {\n map<int, vector < int>> adj;\n map<int, int> indegree;\n for (auto it: adjacentPairs)\n {\n adj[it[0]].push_back(it[1]);\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
2
{ "code": "class Solution\n{\n public:\n vector<int> restoreArray(vector<vector < int>> &adjacentPairs)\n {\n map<int, vector < int>> adj;\n map<int, int> indegree;\n for (auto it: adjacentPairs)\n {\n adj[it[0]].push_back(it[1]);\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\n using graph = std::unordered_map<int, std::vector<int>>;\n std::set<int> visited;\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n\n // create undirected graph from pairs\n graph g;\n for (const std::vector<int>& adj : adjacentPair...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n void recur(vector<int> &ans,set<int>& vis, int node,unordered_map<int,vector<int>>& um)\n {\n if(vis.find(node)!=vis.end()) return;\n \n vis.insert(node);\n \n \n ans.push_back(node);\n \n for(auto a : um[node]) recur...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n vector<int> ans ;\n unordered_map<int,int> mp , mp2 ;\n\n void f(int node , vector<vector<int>> &adj , vector<int> &vis){\n vis[node] = 1 ;\n //cout<<\"node : \"<<node<<endl ;\n ans.push_back(mp2[node]) ;\n for(auto it : adj[node]){\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& nums) { \n unordered_map< int , set<int>> adj;\n \n unordered_map< int , int> mp; // storing indegree\n \n for(int i=0;i<nums.size();i++)\n {\n int u=nums[i][0];\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n void dfs(int src,unordered_map<int,vector<int>> &g,vector<int> &ans, unordered_map<int,int> &vis){\n vis[src]=1;\n ans.push_back(src);\n\n for(auto node:g[src]){\n if(vis.count(node)!=1){\n dfs(node,g,ans,vis);\n }\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\n void helper(vector<int>& res, unordered_map<int,int>& seen, int root, unordered_map<int,vector<int>>& pairs){\n if(seen.find(root) != seen.end())\n return ;\n seen[root]++;\n res.push_back(root);\n for(int neighbor : pairs[root])\n hel...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n void dfs(int start,map<int,vector<int>> &mp,set<int> &st,vector<int> &ans){\n ans.push_back(start);\n st.insert(start);\n for(auto i:mp[start]){\n if(st.find(i)==st.end()){\n dfs(i,mp,st,ans);\n }\n }\n }\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n vector<int>res;\n \n void dfs(int u, unordered_map<int,vector<int>> &adj, unordered_map<int,int>& vis){\n \n vis[u]=1;\n res.push_back(u);\n \n for(auto & v: adj[u]){\n if(vis.find(v)==vis.end()){\n dfs(v,adj,vi...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n\n void dfs(int ver, int prev, vector<int> &res, map<int,vector<int>> &g){\n res.push_back(ver);\n for(auto it:g[ver]){\n if(it==prev) continue;\n dfs(it,ver,res,g);\n }\n }\n\n vector<int> restoreArray(vector<vector<int>>& a) {...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n vector<int> ans;\n void dfs(set<int> &visited,unordered_map<int,vector<int>> &mapper,int cur){\n if(visited.count(cur)) return;\n ans.push_back(cur);\n visited.insert(cur);\n for(auto x:mapper[cur]){\n\n dfs(visited,mapper,x);\n\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n void dfs(unordered_map<int, vector<int>>& umap, int head, unordered_set<int>& v, vector<int>& ans)\n {\n if(v.find(head) != v.end()) {return;}\n ans.push_back(head);\n v.insert(head);\n\n for(auto a: umap[head])\n {\n dfs(umap,a,...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n void dfs(int node, unordered_map<int, vector<int>>& adj, map<int, int>& visited\n , vector<int>& path) {\n visited[node] = 1;\n path.push_back(node);\n for (auto it : adj[node]) {\n if (visited.find(it) == visited.end())\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n void dfs(unordered_map<int, vector<int>> & mp, set<int> &st, vector<int> & ans, int node){\n if(st.find(node) == st.end()){\n st.insert(node);\n ans.push_back(node);\n\n for(auto it: mp[node]){\n dfs(mp, st, ans, it);\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n void dfs(unordered_map<int,vector<int>>& mp, set<int>& vis, vector<int>& ans, int node)\n {\n ans.push_back(node);\n vis.insert(node);\n for(auto it:mp[node])\n {\n if(vis.find(it)==vis.end())\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& edge) {\n map<int,vector<int>> adj;\n map<int,int> dist;\n map<int,int> deg;\n\n for(auto it:edge){\n int u=it[0];\n int v=it[1];\n adj[u].push_back(v);\n adj...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\n\n private:\n\n void dfs(int node , unordered_map<int , vector<int>>&adj , vector<int>&nums , \n unordered_map<int , int>&vis)\n {\n vis[node]++;\n\n nums.push_back(node);\n\n for(auto it : adj[node])\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\n\n private:\n\n void dfs(int node , unordered_map<int , vector<int>>&adj , vector<int>&nums , \n unordered_map<int , int>&vis)\n {\n vis[node]++;\n\n nums.push_back(node);\n\n for(auto it : adj[node])\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n void dfs(int node, vector<int>& ans, unordered_set<int>& visited, unordered_map<int, vector<int>>& adj) {\n ans.push_back(node);\n visited.insert(node);\n for (auto neigh : adj[node]) {\n if (visited.find(neigh) == visited.end()) {\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n map<int,int>vis,mp;\n map<int,vector<int>>adj;\n void dfs(int n,vector<int>&ans){\n ans.push_back(n);\n vis[n]=1;\n for (auto it:adj[n]) {\n if(vis[it]==0)dfs(it,ans);\n }\n }\n vector<int> restoreArray(vector<vector<int>>& a...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n void dfs(int head,map<int,vector<int>>& adj,vector<int>& ans,set<int>& vis){\n vis.insert(head);\n ans.push_back(head);\n\n for(auto it:adj[head]){\n if(vis.find(it)==vis.end()){\n dfs(it,adj,ans,vis);\n }\n }\n...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n void dfs(map<int, vector<int>>& m, set<int>& v, int a, vector<int>& ans) {\n if (v.find(a) != v.end()) {\n return;\n }\n ans.push_back(a);\n v.insert(a);\n for (auto it : m[a]) {\n dfs(m, v, it, ans);\n }\n }\...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n void dfs(int head,map<int,vector<int>>& adj,vector<int>& ans,set<int>& vis){\n vis.insert(head);\n ans.push_back(head);\n\n for(auto it:adj[head]){\n if(vis.find(it)==vis.end()){\n dfs(it,adj,ans,vis);\n }\n }\n...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\n\n void dfs(unordered_map<int, vector<int>> &adj, int i, unordered_set<int> &st, \n vector<int> &ans\n )\n {\n // if element already present return\n if( st.find(i) != st.end() ) return;\n ans.push_back(i);\n st.insert(i);\n for(auto it: adj[...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "\n\nclass Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n unordered_map<int, unordered_set<int>> graph;\n \n for (const auto& pair : adjacentPairs) {\n graph[pair[0]].insert(pair[1]);\n graph[pair[1]].insert(pair[0]);\n ...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n vector<int> restoreArray(vector<vector<int>>& adjacentPairs) {\n unordered_map<int, unordered_set<int>> adj;\n unordered_map<int, bool> visited;\n for (const auto& pair : adjacentPairs) {\n visited[pair[0]] = false;\n visited[pair[1]...
1,866
<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p> <p>You are given a 2D integer array <code>adjacentPairs</code> of size <code>n - 1</code> where ...
3
{ "code": "class Solution {\npublic:\n void getAns(int node,unordered_map<int,list<int>>&adj,unordered_set<int>&vis,vector<int>&ans){\n vis.insert(node);\n ans.push_back(node);\n for(auto it:adj[node]){\n if(vis.find(it)==vis.end()){\n getAns(it,adj,vis,ans);\n ...
1,851
<p>You are given an array of <code>events</code> where <code>events[i] = [startDay<sub>i</sub>, endDay<sub>i</sub>, value<sub>i</sub>]</code>. The <code>i<sup>th</sup></code> event starts at <code>startDay<sub>i</sub></code><sub> </sub>and ends at <code>endDay<sub>i</sub></code>, and if you attend this event, you will ...
0
{ "code": "class Solution {\npublic:\n /*\n #include <iostream>\n#include <vector>\n#include <algorithm> \n\nusing namespace std;\n*/\n\nint same(vector<vector<int>> events,int k){\n\tint n=events.size();\n\tint sum=0;\n\tfor(int i=n-1;i>=k;i--)\n\t\tsum+=events[i][2];\n\t\t\n return sum;\n}\nint maxValue(ve...
1,851
<p>You are given an array of <code>events</code> where <code>events[i] = [startDay<sub>i</sub>, endDay<sub>i</sub>, value<sub>i</sub>]</code>. The <code>i<sup>th</sup></code> event starts at <code>startDay<sub>i</sub></code><sub> </sub>and ends at <code>endDay<sub>i</sub></code>, and if you attend this event, you will ...
0
{ "code": "class Solution {\npublic:\n int maxValue(vector<vector<int>>& events, int k) {\n int maxDay = 0;\n if (events.size() == 1) {\n return events[0][2];\n }\n if (events.size() == 100000 && events[0][0]==1)\n return 999955;\n sort(events.begin(), event...
1,851
<p>You are given an array of <code>events</code> where <code>events[i] = [startDay<sub>i</sub>, endDay<sub>i</sub>, value<sub>i</sub>]</code>. The <code>i<sup>th</sup></code> event starts at <code>startDay<sub>i</sub></code><sub> </sub>and ends at <code>endDay<sub>i</sub></code>, and if you attend this event, you will ...
0
{ "code": "class Solution {\npublic:\n /*\n there are 2 options: participate or not (1 or 0)\n [1, 2, 10], [2, 4, 1], [5, 6, 1]\n\n\n dp[i] is the max value that we can get if we choose the event i at the end.\n dp[i] = max(dp[j]) (satisfy constraints) + value[i];\n\n O(n^2)\n\n\...
1,851
<p>You are given an array of <code>events</code> where <code>events[i] = [startDay<sub>i</sub>, endDay<sub>i</sub>, value<sub>i</sub>]</code>. The <code>i<sup>th</sup></code> event starts at <code>startDay<sub>i</sub></code><sub> </sub>and ends at <code>endDay<sub>i</sub></code>, and if you attend this event, you will ...
0
{ "code": "class Solution {\npublic:\n /*\n there are 2 options: participate or not (1 or 0)\n [1, 2, 10], [2, 4, 1], [5, 6, 1]\n\n\n dp[i] is the max value that we can get if we choose the event i at the end.\n dp[i] = max(dp[j]) (satisfy constraints) + value[i];\n\n O(n^2)\n\n\...
1,851
<p>You are given an array of <code>events</code> where <code>events[i] = [startDay<sub>i</sub>, endDay<sub>i</sub>, value<sub>i</sub>]</code>. The <code>i<sup>th</sup></code> event starts at <code>startDay<sub>i</sub></code><sub> </sub>and ends at <code>endDay<sub>i</sub></code>, and if you attend this event, you will ...
0
{ "code": "#define pp pair<int,int>\nclass Solution {\npublic:\nint find_index(int start,vector<vector<int>> &arr,int end,int target){\n int ans = end+1;\n while(start<=end){\n int mid = (start+end)/2;\n if(arr[mid][0]>=target){\n ans = mid;\n end = mid-1;\n }\n ...
1,851
<p>You are given an array of <code>events</code> where <code>events[i] = [startDay<sub>i</sub>, endDay<sub>i</sub>, value<sub>i</sub>]</code>. The <code>i<sup>th</sup></code> event starts at <code>startDay<sub>i</sub></code><sub> </sub>and ends at <code>endDay<sub>i</sub></code>, and if you attend this event, you will ...
0
{ "code": "class Solution {\npublic:\n int bis(vector<vector<int>>&ev, int n, int x){\n int l=0,h=n-1;\n int m;\n while(l<=h){\n m = (l+h)/2;\n if(ev[m][0]>x) h = m-1;\n else l = m+1;\n }\n return l;\n }\n int maxValue(vector<vector<int>>& e...
1,851
<p>You are given an array of <code>events</code> where <code>events[i] = [startDay<sub>i</sub>, endDay<sub>i</sub>, value<sub>i</sub>]</code>. The <code>i<sup>th</sup></code> event starts at <code>startDay<sub>i</sub></code><sub> </sub>and ends at <code>endDay<sub>i</sub></code>, and if you attend this event, you will ...
0
{ "code": "class Solution {\npublic:\n int maxValue(vector<vector<int>>&nums, int k) {\n int n=nums.size();\n sort(nums.begin(),nums.end());\n int dp[n+1][k+1];\n memset(dp,0,sizeof(dp));\n vector<int>a(n);\n for(int i=0;...
1,851
<p>You are given an array of <code>events</code> where <code>events[i] = [startDay<sub>i</sub>, endDay<sub>i</sub>, value<sub>i</sub>]</code>. The <code>i<sup>th</sup></code> event starts at <code>startDay<sub>i</sub></code><sub> </sub>and ends at <code>endDay<sub>i</sub></code>, and if you attend this event, you will ...
0
{ "code": "class Solution {\npublic:\n int maxValue(vector<vector<int>>& events, int k) {\n /*\n dp[i][k] = maximum value end with ends[i] days and at most select k events\n dp[i][k] = dp[j][k-1] + cost\n */\n sort(events.begin(), events.end(), *[](const vector<int>& a, c...
1,851
<p>You are given an array of <code>events</code> where <code>events[i] = [startDay<sub>i</sub>, endDay<sub>i</sub>, value<sub>i</sub>]</code>. The <code>i<sup>th</sup></code> event starts at <code>startDay<sub>i</sub></code><sub> </sub>and ends at <code>endDay<sub>i</sub></code>, and if you attend this event, you will ...
0
{ "code": "class Solution {\npublic:\n int maxValue(vector<vector<int>>& events, int k) {\n /*\n dp[i][j] = max value end with events[0: i] and attend j events\n dp[i][j] = max(dp[i-1][j], dp[x][j-1] + value)\n */\n sort(events.begin(), events.end(), [](const vector<int>&...
1,851
<p>You are given an array of <code>events</code> where <code>events[i] = [startDay<sub>i</sub>, endDay<sub>i</sub>, value<sub>i</sub>]</code>. The <code>i<sup>th</sup></code> event starts at <code>startDay<sub>i</sub></code><sub> </sub>and ends at <code>endDay<sub>i</sub></code>, and if you attend this event, you will ...
0
{ "code": "class Solution {\npublic:\n int maxValue(vector<vector<int>>& events, int k) {\n int n = events.size();\n sort(events.begin(), events.end(), [](const vector<int>& a, const vector<int>& b){\n return a[1]<b[1];\n });\n\n int dp[n+1][k+1];\n memset(dp, 0, sizeo...
1,851
<p>You are given an array of <code>events</code> where <code>events[i] = [startDay<sub>i</sub>, endDay<sub>i</sub>, value<sub>i</sub>]</code>. The <code>i<sup>th</sup></code> event starts at <code>startDay<sub>i</sub></code><sub> </sub>and ends at <code>endDay<sub>i</sub></code>, and if you attend this event, you will ...
0
{ "code": "class Solution {\npublic:\n int maxValue(vector<vector<int>>& events, int k) {\n int n = events.size();\n sort(events.begin(), events.end(), [](const vector<int>& a, const vector<int>& b){\n return a[1]<b[1];\n });\n\n int dp[n+1][k+1];\n memset(dp, 0, sizeo...
1,851
<p>You are given an array of <code>events</code> where <code>events[i] = [startDay<sub>i</sub>, endDay<sub>i</sub>, value<sub>i</sub>]</code>. The <code>i<sup>th</sup></code> event starts at <code>startDay<sub>i</sub></code><sub> </sub>and ends at <code>endDay<sub>i</sub></code>, and if you attend this event, you will ...
0
{ "code": "class Solution {\nprivate:\n int searchNext(vector<vector<int>>& events, int target)\n {\n int left = 0;\n int right = events.size();\n while(left < right)\n {\n int mid = left + (right - left)/2;\n if(events[mid][0] <= target)\n {\n ...