id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 2 | {
"code": "class Solution {\npublic:\n typedef long long ll;\n typedef pair<ll, ll> pll;\n const ll inf = 1e17;\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n vector<ll> min_time(n, inf);\n min_time[0] = 0;\n vector<vector<pair<ll, ll>>> g(n);\n... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings,\n int firstPerson) {\n vector<pair<int, int>> graph[n];\n vector<int> dis(n, 1e9), res;\n for (auto meet : meetings) {\n int u = meet[0], v = meet[1], ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 2 | {
"code": "class Solution\n{\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) \n {\n set<int> ans;\n \n vector<pair<int, int>> adj[n];\n for(auto i : meetings)\n {\n adj[i[0]].push_back({i[1], i[2]});\n adj[i[1]]... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n class DisjointSet {\n public:\n vector<int> parent, size;\n\n DisjointSet(int n) {\n parent.resize(n);\n size.resize(n, 1);\n for (int i = 0; i < n; i++)\n parent[i] = i;\n }\n int findUPar(int x) ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\n typedef pair<int,int>P;\n\n void dfs(int person1, int time, unordered_map<int, vector<P>>& adj, vector<int>& earlySecretTime) {\n for(auto &nbr:adj[person1]){\n int person=nbr.first;\n int t=nbr.second;\n if(t>=time && earlySecretTime[person... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n typedef pair<int,int> p;\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n \n map<int,vector<p>> adj; // person -> person , time\n for(auto i : meetings){\n adj[i[0]].push_back({i[1],i[2]});\n ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n typedef pair<int, int> ii;\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n multiset<ii> ms;\n ms.insert({0, 0});\n ms.insert({0, firstPerson});\n vector<int> know(n, 1e9);\n know[0] = 0, know[firstPe... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n vector<vector<pair<int, int>>> graph(n, vector<pair<int, int>>());\n vector<int> shortestPath(n, INT_MAX);\n shortestPath[0] = 0;\n shortestPath[firstPerson] = 0;\... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n int find(vector<int>& dsu, int index) {\n vector<int> path;\n\n while (dsu[index] >= 0) {\n path.push_back(index);\n index = dsu[index];\n }\n\n for (int i : path) {\n dsu[i] = index;\n }\n\n return in... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n sort(begin(meetings), end(meetings), [](const auto& a, const auto& b) { return a[2] < b[2]; });\n unordered_set<int> result = {0, firstPerson};\n unordered_map<int, vecto... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "\n\n\nclass Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n vector<vector<vector<int>>> adj(n);\n for(auto &met:meetings){\n adj[met[0]].push_back({met[1], met[2]});\n adj[met[1]].push_back({met[0], met[2]});\... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class disjoint_set\n{\n int* size;\n int* parent;\n\n public:\n disjoint_set(int n)\n {//constructor, using plain arrays for s p e e d\n size = new int[n];\n for (int i = 0; i <= n-1; i++) size[i] = 1;\n\n parent = new int[n];\n for (int i = 0; i <= n-1; i++) pare... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class disjoint_set\n{\n int* size;\n int* parent;\n\n public:\n disjoint_set(int n)\n {//constructor, using plain arrays for s p e e d\n size = new int[n];\n for (int i = 0; i <= n-1; i++) size[i] = 1;\n\n parent = new int[n];\n for (int i = 0; i <= n-1; i++) pare... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n vector<vector<int>>adj[n];\n for (int i = 0 ; i < meetings.size() ; i++){\n int u = meetings[i][0]; int v = meetings[i][1]; int wt = meetings[i][2];\n adj[... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "struct dsu\n{\n vector<int> parent, sz;\n void init(int n)\n {\n parent = vector<int>(n + 10), sz = vector<int>(n + 10, 1);\n for(int i = 0; i <= n; i++) parent[i] = i;\n } \n\n int find(int x)\n {\n if(parent[x] == x) return x;\n else return parent[x] = find(... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n int find(vector<int> &parent,int val){\n if(parent[val] != val) parent[val] = find(parent,parent[val]);\n return parent[val];\n }\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n // sort(meetings.begin(),meeting... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& a, int F){\n map<int, map<int, vector<int>>> adj;\n for(auto &vv : a){\n int u = vv[0], v = vv[1], t = vv[2];\n adj[t][u].push_back(v);\n adj[t][v].push_back(u);\n }\n ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\n\n void findMinTimeToDiscoverSecret(\n unordered_map< int, list< pair<int, int> > >& graph,\n vector<int>& discoveryTime,\n int firstPerson\n ){\n // Declare the required data structure\n multimap< int, int> pq;\n unordered_map<int, int> vis... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n map<int,vector<pair<int,int>>>mp;\n unordered_map<int,int>secret;\n vector<vector<pair<int,int>>>g;\nvoid dfs(int nn,int t){\n secret[nn]=1;\n for(auto [adj,edwt]:g[nn]){\n if(edwt==t && secret[adj]==0){\n dfs(adj,t);\n }\n }\n}\n vector<int> findAl... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n int Find (int a, vector<int>& p) {\n return p[a] == a ? a : p[a] = Find(p[a], p);\n }\n\n void Union (int a, int b, vector<int>& p) {\n p[Find(a, p)] = Find(b, p);\n }\n\n void Reset (int a, vector<int>& p) {\n p[a] = a;\n }\n\n void Ini... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n \n map<int,vector<int>> personsMeeting; \n for (int c = 0;c<meetings.size();++c){\n personsMeeting[meetings[c][0]].push_back(c);\n personsMeeting[mee... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n \n map<int,vector<int>> personsMeeting; \n for (int c = 0;c<meetings.size();++c){\n personsMeeting[meetings[c][0]].push_back(c);\n personsMeeting[mee... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n vector<int>reached(n,1e9);\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;\n reached[0]=0;\n reached[firstPerson]=0;\n pq.pu... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings,\n int firstPerson) {\n\n map<int, vector<pair<int, int>>> mp;\n for (auto& it : meetings) {\n int u = it[0];\n int v = it[1];\n int t = ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n vector<vector<int>> adj[n];\n adj[0].push_back({firstPerson,0});\n for(auto it:meetings){\n int x= it[0],y= it[1], z = it[2];\n adj[x].push_back({y,... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class DJ {\npublic:\n DJ(int N) : N(N) {\n init();\n }\n vector<int> parent, rank, count, point;\n\n void init() {\n parent.resize(N);\n rank.resize(N);\n count.resize(N);\n point.resize(N);\n for (int i=0; i<N; i++) {\n parent[i] = i;\n ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution\r\n{\r\npublic:\r\n set<int> bigset;\r\n void dfs(int elem, unordered_map<int, vector<int>> &um, set<int> &smallset)\r\n {\r\n smallset.insert(elem);\r\n for (int x : um[elem])\r\n {\r\n if (smallset.find(x) != smallset.end())\r\n conti... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n\n vector<vector<int>> adj[n];\n\n for(auto it:meetings){\n adj[it[0]].push_back({it[1],it[2]});\n adj[it[1]].push_back({it[0],it[2]});\n }\n\n ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& m, int fp) {\n vector<vector<vector<int>>> g(n);\n for(auto item : m){\n g[item[0]].push_back({item[1],item[2]});\n g[item[1]].push_back({item[0],item[2]});\n }\n vector<i... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meet, int start) {\n vector<vector<vector<int>>> g(n);\n for(auto &e:meet){\n g[e[0]].push_back({e[2],e[1]});\n g[e[1]].push_back({e[2],e[0]});\n }\n for(int i=0; i<n; i++)... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\n\n void dfs(int curr, set<int> &known, set<int> &visited, map<int, vector<int>> const& adj) {\n if (visited.find(curr) != visited.end()) {\n return;\n }\n visited.insert(curr);\n known.insert(curr);\n\n for (int nbr: adj.at(curr)) {\n ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> f;\n int find(int x){\n if(f[x] == x) return x;\n return f[x] = find(f[x]);\n }\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n map<int, vector<vector<int>>> mp;\n for(vector<int> m : meet... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& edges,\n int firstPerson) {\n vector<vector<int>> adj[n];\n for (auto x : edges) {\n int u = x[0], v = x[1], wt = x[2];\n adj[u].push_back({v, wt});\n ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution \n{\nprivate:\n vector<bool> isKnown;\n \npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) \n {\n //cout<<n<<\" \"<<meetings.size()<<endl;\n \n map<int, vector<vector<int>>> groups;\n for (auto& it : meetings)\... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\n\n void dfs(int curr, set<int> &known, set<int> &visited, unordered_map<int, vector<int>> const& adj) {\n if (visited.find(curr) != visited.end()) {\n return;\n }\n visited.insert(curr);\n known.insert(curr);\n\n for (int nbr: adj.at(curr))... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution \n{\nprivate:\n vector<bool> isKnown;\n vector<int> vis;\n\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) \n {\n //cout<<n<<\" \"<<meetings.size()<<endl;\n \n map<int, vector<vector<int>>> groups;\n for (aut... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n map<int, vector<pair<int, int>>> mp;\n mp[0].push_back({0, firstPerson});\n for (auto && m : meetings) {\n int x = m[0], y = m[1], t = m[2];\n mp[t]... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\n\n void dfs(int curr, unordered_set<int> &known, unordered_set<int> &visited, unordered_map<int, vector<int>> const& adj) {\n if (visited.find(curr) != visited.end()) {\n return;\n }\n visited.insert(curr);\n known.insert(curr);\n\n for (in... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n vector<int> kwn(n, -1);\n vector<int> ans;\n \n priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> pque;\n \n pque.push({0, 0});\... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n map<int , set<pair<int,int>>> m;\n // SORTING TIME WISE\n for(int i=0 ; i<meetings.size() ; i++)\n {\n int p1 = meetings[i][0];\n int p2 = me... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meet, int start) {\n vector<vector<vector<int>>> g(n);\n for(auto &e:meet){\n g[e[0]].push_back({e[2],e[1]});\n g[e[1]].push_back({e[2],e[0]});\n }\n for(int i=0; i<n; i++)... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n int find(int n,vector<int>&par){\n if(par[n]<0){\n return n;\n }\n return par[n]=find(par[n],par);\n }\n\n void unite(int a, int b,vector<int>&par,vector<int>&rnk){\n a=find(a,par);\n b=find(b,par);\n if(a==b){\n ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n int find(int n,vector<int>&par){\n if(par[n]<0){\n return n;\n }\n return par[n]=find(par[n],par);\n }\n\n void unite(int a, int b,vector<int>&par,vector<int>&rnk){\n a=find(a,par);\n b=find(b,par);\n if(a==b){\n ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n void f(int node ,int time,map<int,vector<vector <int>>>&adj,vector <int> &vst)\n {\n for (auto i: adj[node])\n {\n // only increasing and vst to track shortest time \n if (time<=i[1] and vst[i[0]]>i[1])\n {\n vst[i[0]]=i[1];\n ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\nint par[100005],sz[100005];\n\n int find(int i){\n if(i!=par[i])par[i] = find(par[i]);\n return par[i];\n }\n\n void uni(int x,int y){\n int a = find(x),b =find(y);\n if(a!=b){\n if(sz[a]<sz[b])swap(a,b);\n par[b] = a;\n ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n void dfs(unordered_map<int, list<int>>& g, int v, vector<bool>& knows, unordered_set<int>& seen)\n {\n if (seen.count(v))\n {\n return;\n }\n seen.emplace(v);\n knows[v] = true;\n for (auto e : g[v])\n {\n ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n struct comp{\n bool operator() (vector<int> &a, vector<int> &b){\n return a[0]>b[0];\n }\n };\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n vector<vector<int>> G[n];\n\n for(auto m:meetings)... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n struct comp{\n bool operator() (vector<int> &a, vector<int> &b){\n return a[0]>b[0];\n }\n };\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n vector<vector<int>> G[n];\n\n for(auto m:meetings)... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n bool static sortFunc(vector<int> &a, vector<int> &b){\n return a[2] < b[2];\n }\n\n void traversal(int node, unordered_map<int, int> &vis, unordered_map<int, vector<int>> &m, unordered_set<int> &s){\n\n if(vis[node] == 0) return;\n vis[node] = 0;\n ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "#include <vector>\n#include <queue>\n#include <map>\n#include <utility> // for std::pair\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int fp) {\n int m = meetings.size();\n \n if (m == 0) return {fp}; // Handl... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n typedef long long ll;\n\n // Function used to sort the array in the non-decreasing time stamp.\n static bool cmp(vector<int> &v1, vector<int> &v2){\n return v1[2]<v2[2];\n }\n vector<int> findAllPeople(int n, vector<vector<int>>& arr, int f) {\n // ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n typedef long long ll;\n\n // Function used to sort the array in the non-decreasing time stamp.\n static bool cmp(vector<int>& v1, vector<int>& v2) { return v1[2] < v2[2]; }\n vector<int> findAllPeople(int n, vector<vector<int>>& arr, int f) {\n // Vector that... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n sort(meetings.begin(), meetings.end(), [](auto& a, auto& b) {\n return a[2] < b[2];\n });\n unordered_map<int, vector<int>> adjList;\n int time = meetin... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n map<int, vector<vector<int>>> meetingsAtTime;\n vector<int> knowsSecret(n), ans;\n queue<int> q;\n\n ranges::for_each(meetings, [&](const auto& meeting) {\n ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\nclass DisjointSet{\n unordered_map<int,int>rank,parent,size;\npublic:\n DisjointSet(vector<int>a){\n for(auto i:a){\n parent[i]=i;\n size[i]=1;\n }\n \n }\n int findUpar(int node){\n if(node==parent[node]) return node;\n return parent[node]=findUpa... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\nclass DisjointSet{\n unordered_map<int,int>rank,parent,size;\npublic:\n DisjointSet(vector<int>a){\n for(auto i:a){\n parent[i]=i;\n size[i]=1;\n }\n \n }\n int findUpar(int node){\n if(node==parent[node]) return node;\n return parent[node]=findUpa... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\nclass DisjointSet{\n map<int,int>rank,parent,size;\npublic:\n DisjointSet(vector<int>a){\n for(auto i:a){\n parent[i]=i;\n size[i]=1;\n }\n \n }\n int findUpar(int node){\n if(node==parent[node]) return node;\n return parent[node]=findUpar(parent[n... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n\n void dfs(int src, unordered_set<int> &visited, map<int, vector<int>> &adj, unordered_set<int> &secrets){\n if(visited.find(src) != visited.end())\n return;\n\n visited.insert(src);\n\n secrets.insert(src);\n\n for(auto &neigh : adj[src... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n bool dfs(map<int, vector<int>> &grph, int node, map<int,int> &vis, set<int> &knew){\n vis[node]=1;\n bool ans=false;\n for(auto child:grph[node]){\n if(vis[child]) continue;\n ans = ans | dfs(grph, child, vis, knew);\n }\n ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "#include <iostream>\n#include <vector>\n#include <unordered_set>\n#include <algorithm>\n#include <queue>\n\nclass Solution {\npublic:\n std::vector<int> findAllPeople(int n, std::vector<std::vector<int>>& meetings, int firstPerson) {\n // Initial step: Person 0 shares the secret with firstPerson ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "#include <iostream>\n#include <vector>\n#include <map>\n#include <queue>\n#include <unordered_map>\n#include <unordered_set>\n#include <algorithm>\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n // Map to ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings,\n int firstPerson) {\n // Sort meetings in increasing order of time\n // sort(meetings.begin(), meetings.end(),\n // [](auto& a, auto& b) { return a[2] < b[2... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n \n sort(meetings.begin(), meetings.end(), [](auto& a, auto& b) {\n return a[2]<b[2];\n });\n\n map<int, vector<pair<int,int>>> sameTimeMeetings;\n ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "/* Scroll down to see JAVA code also */\n/*\n MY YOUTUBE VIDEO ON THIS Qn : https://www.youtube.com/watch?v=hxEWwnJJKcY\n Company Tags : GOOGLE\n Leetcode Link : https://leetcode.com/problems/find-all-people-with-secret/\n*/\n\n\n/****... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n typedef pair<int, int> P;\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n\n map<int, vector<P>> timeMeetings;\n \n for(vector<int>& meeting : meetings) {\n int person1 = meeting[0];\n int per... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n void bfs(queue<int>&q, unordered_map<int,vector<int>>&adj, vector<bool>&secret){\n int n = secret.size();\n // vector<int>vis(n,0);\n \n while(!q.empty()){\n int node = q.front();\n q.pop();\n for(auto &adjNode:adj[... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int start) {\n sort(meetings.begin(), meetings.end(), [&](vector<int> &a, vector<int> &b){\n return a[2] < b[2];\n });\n\n map<int, vector<pair<int, int>>> mp;\n for(auto it... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n vector<bool> visited(n, false); // Initialize all elements to false\n visited[firstPerson] = true;\n visited[0] = true;\n\n map<int, vector<pair<int, int>>> mp;\n ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n typedef pair<int,int> p;\n vector<int> findAllPeople(int n, vector<vector<int>>& meeting, int firstperson) {\n map<int,vector<p>> timemeet;\n\n for(auto i : meeting){\n timemeet[i[2]].push_back({i[0],i[1]});\n }\n\n vector<bool> ksecr... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n map<int,vector<pair<int,int>>>m;\n for(int i=0;i<meetings.size();i++){\n m[meetings[i][2]].push_back({meetings[i][0],meetings[i][1]});\n }\n vector<bool... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n\n void dfs(int src, unordered_set<int> &visited, map<int, vector<int>> &adj, unordered_set<int> &secrets){\n if(visited.find(src) != visited.end())\n return;\n\n visited.insert(src);\n\n secrets.insert(src);\n\n for(auto &neigh : adj[src... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n\n void dfs(int src, unordered_set<int> &visited, map<int, vector<int>> &adj, unordered_set<int> &secrets){\n if(visited.find(src) != visited.end())\n return;\n\n visited.insert(src);\n\n secrets.insert(src);\n\n for(auto &neigh : adj[src... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& m, int p) {\n map<int,vector<pair<int,int>>> mp;\n for(auto it:m)\n {\n mp[it[2]].push_back({it[0],it[1]});\n \n }\n vector<int> ans(n,0);\n ans[0]=1;\n ans[p]=1;\... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n vector<int> res;\n map<int,vector<pair<int,int>>> mmp;\n // time:1 person:0 -> 1\n // time:2 person:0 -> 1 -> 2 -> 3\n // 记录知道秘密的人\n vector<int> pm... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n auto myComp = [](vector<int>& a,vector<int>& b){\n return a[2]<b[2];\n };\n\n sort(meetings.begin(),meetings.end(),myComp);\n vector<int>visited(n,0);\n... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meetings, int firstPerson) {\n // 0 untouched , 1 - vis, 2 has secret;\n vector<int> status(n, 0);\n vector<int> ans;\n ans.push_back(0);\n ans.push_back(firstPerson);\n status[0] ... |
2,213 | <p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates tha... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findAllPeople(int n, vector<vector<int>>& meet, int f) {\n int k=meet.size();\n map<int,vector<pair<int,int>>>adj;\n for(auto it:meet) adj[it[2]].push_back({it[0],it[1]});\n vector<int>vis(n,0);vis[0]=1;vis[f]=1;\n for(auto it:ad... |
2,216 | <p>You are given the <code>head</code> of a linked list. <strong>Delete</strong> the <strong>middle node</strong>, and return <em>the</em> <code>head</code> <em>of the modified linked list</em>.</p>
<p>The <strong>middle node</strong> of a linked list of size <code>n</code> is the <code>⌊n / 2⌋<sup>th</s... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n #pragma GCC optimize(\"O3,... |
2,216 | <p>You are given the <code>head</code> of a linked list. <strong>Delete</strong> the <strong>middle node</strong>, and return <em>the</em> <code>head</code> <em>of the modified linked list</em>.</p>
<p>The <strong>middle node</strong> of a linked list of size <code>n</code> is the <code>⌊n / 2⌋<sup>th</s... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n\n#pragma GCC optimize(\"O3... |
2,216 | <p>You are given the <code>head</code> of a linked list. <strong>Delete</strong> the <strong>middle node</strong>, and return <em>the</em> <code>head</code> <em>of the modified linked list</em>.</p>
<p>The <strong>middle node</strong> of a linked list of size <code>n</code> is the <code>⌊n / 2⌋<sup>th</s... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n #pragma GCC optimize(\"O3,... |
2,216 | <p>You are given the <code>head</code> of a linked list. <strong>Delete</strong> the <strong>middle node</strong>, and return <em>the</em> <code>head</code> <em>of the modified linked list</em>.</p>
<p>The <strong>middle node</strong> of a linked list of size <code>n</code> is the <code>⌊n / 2⌋<sup>th</s... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n#pragma GCC optimize(\"O3,u... |
2,216 | <p>You are given the <code>head</code> of a linked list. <strong>Delete</strong> the <strong>middle node</strong>, and return <em>the</em> <code>head</code> <em>of the modified linked list</em>.</p>
<p>The <strong>middle node</strong> of a linked list of size <code>n</code> is the <code>⌊n / 2⌋<sup>th</s... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n #pragma GCC optimize(\"O3... |
2,216 | <p>You are given the <code>head</code> of a linked list. <strong>Delete</strong> the <strong>middle node</strong>, and return <em>the</em> <code>head</code> <em>of the modified linked list</em>.</p>
<p>The <strong>middle node</strong> of a linked list of size <code>n</code> is the <code>⌊n / 2⌋<sup>th</s... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n\n#pragma GCC optimize(\"O3... |
2,216 | <p>You are given the <code>head</code> of a linked list. <strong>Delete</strong> the <strong>middle node</strong>, and return <em>the</em> <code>head</code> <em>of the modified linked list</em>.</p>
<p>The <strong>middle node</strong> of a linked list of size <code>n</code> is the <code>⌊n / 2⌋<sup>th</s... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nint init = [] {\n ofstre... |
2,216 | <p>You are given the <code>head</code> of a linked list. <strong>Delete</strong> the <strong>middle node</strong>, and return <em>the</em> <code>head</code> <em>of the modified linked list</em>.</p>
<p>The <strong>middle node</strong> of a linked list of size <code>n</code> is the <code>⌊n / 2⌋<sup>th</s... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nint init = [] {\n ofstre... |
2,216 | <p>You are given the <code>head</code> of a linked list. <strong>Delete</strong> the <strong>middle node</strong>, and return <em>the</em> <code>head</code> <em>of the modified linked list</em>.</p>
<p>The <strong>middle node</strong> of a linked list of size <code>n</code> is the <code>⌊n / 2⌋<sup>th</s... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,216 | <p>You are given the <code>head</code> of a linked list. <strong>Delete</strong> the <strong>middle node</strong>, and return <em>the</em> <code>head</code> <em>of the modified linked list</em>.</p>
<p>The <strong>middle node</strong> of a linked list of size <code>n</code> is the <code>⌊n / 2⌋<sup>th</s... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,217 | <p>You are given the <code>root</code> of a <strong>binary tree</strong> with <code>n</code> nodes. Each node is uniquely assigned a value from <code>1</code> to <code>n</code>. You are also given an integer <code>startValue</code> representing the value of the start node <code>s</code>, and a different integer <code>d... | 0 | {
"code": "#include <string>\n\nclass Solution {\nprivate:\n static char pathBuffer[100001];\n static int pathFront, pathBack;\n static int startNodeValue, endNodeValue;\n \n static int traverseTree(TreeNode* node) {\n if (node == nullptr) return 0;\n if (node->val == endNodeValue) {\n ... |
2,217 | <p>You are given the <code>root</code> of a <strong>binary tree</strong> with <code>n</code> nodes. Each node is uniquely assigned a value from <code>1</code> to <code>n</code>. You are also given an integer <code>startValue</code> representing the value of the start node <code>s</code>, and a different integer <code>d... | 0 | {
"code": "#include <string>\n\nclass Solution {\nprivate:\n static char pathBuffer[100001];\n static int pathFront, pathBack;\n static int startNodeValue, endNodeValue;\n \n static int traverseTree(TreeNode* node) {\n if (node == nullptr) return 0;\n if (node->val == endNodeValue) {\n ... |
2,217 | <p>You are given the <code>root</code> of a <strong>binary tree</strong> with <code>n</code> nodes. Each node is uniquely assigned a value from <code>1</code> to <code>n</code>. You are also given an integer <code>startValue</code> representing the value of the start node <code>s</code>, and a different integer <code>d... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,217 | <p>You are given the <code>root</code> of a <strong>binary tree</strong> with <code>n</code> nodes. Each node is uniquely assigned a value from <code>1</code> to <code>n</code>. You are also given an integer <code>startValue</code> representing the value of the start node <code>s</code>, and a different integer <code>d... | 0 | {
"code": "class Solution {\npublic:\n bool find(TreeNode* n, int val, string& path) {\n if (n->val == val)\n return true;\n if (n->left && find(n->left, val, path))\n path.push_back('L');\n else if (n->right && find(n->right, val, path))\n path.push_back('R');... |
2,217 | <p>You are given the <code>root</code> of a <strong>binary tree</strong> with <code>n</code> nodes. Each node is uniquely assigned a value from <code>1</code> to <code>n</code>. You are also given an integer <code>startValue</code> representing the value of the start node <code>s</code>, and a different integer <code>d... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,217 | <p>You are given the <code>root</code> of a <strong>binary tree</strong> with <code>n</code> nodes. Each node is uniquely assigned a value from <code>1</code> to <code>n</code>. You are also given an integer <code>startValue</code> representing the value of the start node <code>s</code>, and a different integer <code>d... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,217 | <p>You are given the <code>root</code> of a <strong>binary tree</strong> with <code>n</code> nodes. Each node is uniquely assigned a value from <code>1</code> to <code>n</code>. You are also given an integer <code>startValue</code> representing the value of the start node <code>s</code>, and a different integer <code>d... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,217 | <p>You are given the <code>root</code> of a <strong>binary tree</strong> with <code>n</code> nodes. Each node is uniquely assigned a value from <code>1</code> to <code>n</code>. You are also given an integer <code>startValue</code> representing the value of the start node <code>s</code>, and a different integer <code>d... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,217 | <p>You are given the <code>root</code> of a <strong>binary tree</strong> with <code>n</code> nodes. Each node is uniquely assigned a value from <code>1</code> to <code>n</code>. You are also given an integer <code>startValue</code> representing the value of the start node <code>s</code>, and a different integer <code>d... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,217 | <p>You are given the <code>root</code> of a <strong>binary tree</strong> with <code>n</code> nodes. Each node is uniquely assigned a value from <code>1</code> to <code>n</code>. You are also given an integer <code>startValue</code> representing the value of the start node <code>s</code>, and a different integer <code>d... | 2 | {
"code": "class Solution {\n\nprivate:\n void rootToNode(TreeNode* root,int &n,int &m,string &temp,string &s,string &d){\n if(!root) return;\n\n if(root->val == n) s=temp;\n if(root->val == m) d=temp;\n \n temp.push_back('L');\n rootToNode(root->left, n, m, temp, s, d);\n... |
2,217 | <p>You are given the <code>root</code> of a <strong>binary tree</strong> with <code>n</code> nodes. Each node is uniquely assigned a value from <code>1</code> to <code>n</code>. You are also given an integer <code>startValue</code> representing the value of the start node <code>s</code>, and a different integer <code>d... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,217 | <p>You are given the <code>root</code> of a <strong>binary tree</strong> with <code>n</code> nodes. Each node is uniquely assigned a value from <code>1</code> to <code>n</code>. You are also given an integer <code>startValue</code> representing the value of the start node <code>s</code>, and a different integer <code>d... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,217 | <p>You are given the <code>root</code> of a <strong>binary tree</strong> with <code>n</code> nodes. Each node is uniquely assigned a value from <code>1</code> to <code>n</code>. You are also given an integer <code>startValue</code> representing the value of the start node <code>s</code>, and a different integer <code>d... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.