id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
1
{ "code": "/*\n Do this recursively. For each node, let's figure out \n (A) the longest path UP into it \n (B) the longest path DOWN into it\n\n Longest path up is simple DFS.\n\n Two choices for the longest path down -> we can choose one of the \n UP paths into the parent (other than our up path) a...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
1
{ "code": "class Solution {\npublic:\n int longestPath(vector<int>& parent, string s) {\n int n = parent.size();\n vector<int> adj[n];\n for(int i=1; i<n; i++){\n adj[parent[i]].push_back(i);\n adj[i].push_back(parent[i]);\n }\n int ans = 0;\n auto df...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
1
{ "code": "class Solution {\npublic:\n int max(int v1, int v2) {\n if(v1 > v2) return v1;\n \n return v2;\n }\n\n struct s_backtrack {\n int parent;\n int child; // node index\n int longest_len;\n int secondlongest;\n int current_len;\n };\n\n int...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
1
{ "code": "class Solution {\npublic:\nstring s;\nint n;\nint r=0;\nvector<int>adj[100005];\nint dfs(int node,int par){\n int mf=0;\n int ms=0;\n for(auto it:adj[node]){\n if(it==par)continue;\n int child_lenghts=dfs(it,node);\n if(s[it]==s[node])continue;\n if(child_lenghts...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
1
{ "code": "class Solution {\npublic:\n int ans = 1;\n vector<int> dp;\n\n void dfs(int node,int par,vector<int> adj[],string&s){\n priority_queue<int> pq;\n for(auto child:adj[node]){\n if(child==par) continue;\n dfs(child,node,adj,s);\n if(s[child]!=s[node]){\n...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
1
{ "code": "class Solution {\npublic:\n int answer;\n \n int dfs(int node, int p, vector<vector<int>>& adj, string &s) {\n int l = 0;\n int s_l = 0;\n\n for (auto it : adj[node]) {\n if (it != p) {\n int ans = dfs(it, node, adj, s);\n if (s[it] != ...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "struct Node {\n Node(char c) : c(c) {}\n char c;\n std::vector<Node*> children;\n};\n\nclass Solution {\npublic:\n int longestPath(vector<int>& parent, string s) {\n int n = parent.size();\n if (n == 0) {\n return 0;\n }\n std::vector<std::unique_ptr<Node>...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n int ans=0;\n int dp[100001];\n\n void fun(int sr, int p, vector<vector<int>>& adj, string& s)\n {\n dp[sr]=1;\n int m1=0, m2=0;\n for(auto i:adj[sr])\n {\n if(i==p) continue;\n fun(i,sr,adj,s);\n if(s[sr]!=...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n\n int ans;\n\n int dfs(int node, vector<int> adj[], int par,string &s)\n {\n int maxl=0;\n\n for(auto x : adj[node])\n {\n if(x == par) continue;\n \n int y = dfs(x,adj,node,s);\n\n if(s[x] == s[node]) con...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n vector<int> dp;\n vector<vector<int>> tr;\n \n string s1;\n int ans=0;\n void dfs(int src,int par){\n int m1=-1,m2=-1;\n for(auto i:tr[src]){\n if(i==par) continue;\n dfs(i,src);\n if(s1[i]!=s1[src]&&dp[i]>=m2){\n ...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n int longestPath(vector<int>& parent, string global_s) {\n s = global_s;\n int n = s.size();\n g.resize(n);\n for (int i = 0; i < n; i++) {\n g[i].clear();\n }\n for (int i = 1; i < n; i++) {\n g[i].push_back(pare...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n int maxSum;\n int dfs(int node, int parent, vector<vector<int>>& adj, string& s) {\n\n int longest = 0;\n int second_longest = 0;\n\n for (auto child : adj[node]) {\n if (child == parent)\n continue;\n\n int child_l...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n int longestPath(vector<int>& parent, string global_s) {\n s = global_s;\n int n = s.size();\n g.resize(n);\n for (int i = 0; i < n; i++) {\n g[i].clear();\n }\n for (int i = 1; i < n; i++) {\n g[i].push_back(pare...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n int longestPath(vector<int>& parent, string global_s) {\n s = global_s;\n int n = s.size();\n g.resize(n);\n for (int i = 0; i < n; i++) {\n g[i].clear();\n }\n for (int i = 1; i < n; i++) {\n g[i].push_back(pare...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n\nint maxi;\n pair<int,char> solve(int index, vector<vector<int>>&adj, vector<int>&parent,string &s){\n if(index >= adj.size()){\n return {0,'$'};\n }\n\n\n vector<pair<int,char>>v;\n\n for(auto it:adj[index]){\n\n pair<int,char>...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n int result = 1;\n int longestLenFromNode(int node, int par, vector<vector<int>>& tree, string& s){\n int longest = 0;\n int secondLongest = 0;\n for(auto u: tree[node])if(u!=par){\n int childLongest = longestLenFromNode(u, node, tree, s);\n ...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n int dfs(int node, vector<int>adj[], vector<char>&ch, vector<int>&vis, int &ans){\n vis[node]=1;\n vector<int>v;\n // cout<<node<<\": \";\n for(auto &child:adj[node]){\n int x;\n if(vis[child]==0)\n x= dfs(child, ad...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n // every node has which child (index)\n vector<int> child[100005];\n string s;\n int res = 1;\n // the longest path starting from node toward leaves\n vector<int> len;\n void dfs(int i) {\n // if current node does not have child\n if (child[i]....
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\nvector < vector < int > > adj;\n string letters;\n\n int dfs(int u, int p, int& best_path){\n int best_path_1 = 0, best_path_2 = 0;\n \n auto update_max = [&](int x){\n if(x >= best_path_1)\n best_path_2 = best_path_1, best_pat...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> adj;\n string letters;\n\n void add_edge(int u, int v) {\n adj[u].push_back(v);\n adj[v].push_back(u);\n }\n\n int dfs(int u, int p, int& best_path){\n // visit the current node\n int best_path_1 = 0, best_path_2 = 0...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n int result = 1;\n int f(int node, vector<int>& parent, char prev, string& s, vector<vector<int>>& adj){\n int ans = 0;\n vector<int> subTree;\n for(auto it:adj[node]){\n if(it!=parent[node]){\n int temp = 1 + f(it, parent, s[n...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "using ll = long long;\nusing pl = pair<ll, ll>;\nusing vl = vector<ll>;\nusing vvl = vector<vector<ll>>;\nusing vll = vector<pair<ll, ll>>;\n\n#define all(a) a.begin(), a.end()\n#define rall(a) a.rbegin(), a.rend()\n\nclass Solution {\npublic:\n\n\nll dfs(ll cur,ll par,ll &ans,string &s,vvl &g){\n \n ...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n int ans = 0;\n int solve(vector<vector<int>>& graph, string& s,vector<bool>& visited, int i ){\n visited[i] = true;\n int max1 = 0, max2 = 0;\n for(auto& x : graph[i]){\n if(visited[x] == false){\n int a = solve(graph, s , vis...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\nprivate:\n vector<vector<int>> tree;\n string s;\n int res;\n int dfs(int root, char lc)\n {\n int resvalue = -1;\n if(s[root] == lc){\n resvalue = 0;\n }\n\n int v1 = 0;\n vector<int> result;\n for(int i : tree[root]){\n...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n vector<int>adj[100005],v1[100005];\n vector<int>v,v2;\n void dfs(int node,int parent,string &s){\n for(auto it:adj[node]){\n if(it!=parent){\n dfs(it,node,s);\n if(s[it]!=s[node]){\n v1[node].push_back(v...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "// solution\nclass Solution {\npublic:\n int longestPath(vector<int>& parent, string s) {\n int n = parent.size();\n vector<vector<int>> adj(n);\n for (int i = 1; i < n; ++i) {\n adj[parent[i]].push_back(i);\n }\n int ans = 0;\n auto dnc = [&](auto && dnc, int u)->array<int, 2> {\n ...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n string str;\n int ans = 0;\n \n int DFS(vector<vector<int>>& adj, int s) {\n int res = 1;\n vector<int> v;\n \n for (int x : adj[s]) {\n int y = DFS(adj, x);\n if (str[x] != str[s]) v.push_back(y);\n }\n ...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "#define ll long long\nclass Solution {\npublic:\nvector<ll>sc;\nvector<vector<ll>>g;\nvector<ll>pr;\nll ans=0;\nvoid dfs(ll n,string &s){\n sc[n]=1;vector<ll>lp;\n for(auto it:g[n]){\n if(it==pr[n])continue;\n dfs(it,s);\n // cout<<it<<\" \"<<n<<\" \"<<sc[it]<<endl;\n if(s...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n int ans;\n int dfs(int node,int par,vector<int>adj[],string &s) {\n\n int count=0; \n vector<int>temp;\n for(auto &child:adj[node]) {\n if(child == par) continue;\n \n int ct=dfs(child,node,adj,s);\n if(s[...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n int ans;\n int solve(int node,int par,vector<int>adj[],string &s,char ch) { //max Length,char\n \n vector<int>temp;\n int count=0;\n for(auto &child:adj[node]) {\n if(child!=par) {\n int ct=solve(child,node,adj,s,ch);...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\n int dfs(int node,int par,vector<int> adj[],int &ans,string &s)\n {\n int curr=1;\n int maxi=curr;\n vector<int> side;\n for(auto it:adj[node])\n {\n if(it==par)continue;\n if(s[it]==s[node]){\n dfs(it,node,adj,...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n int dfs(int node,vector<int> g[],string &s,int &global_max,vector<int> &vis)\n {\n vector<int> temp;\n\n vis[node] = 1;\n for(auto adj: g[node])\n {\n if(vis[adj] == 1)\n {\n continue;\n }\n\n ...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n int ans=1;\n bool isleaf(int u,vector<int>adj[]){\n if(u!=0 && adj[u].size()==1){\n return true;\n }\n return false;\n }\n void dfs(int node, int par, vector<int> adj[], string &s, vector<vector<int>> &dp) {\n dp[node][0] = dp[node][1] = 0; // In...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n int glob = 1;\n string s = \"\";\n int longestPath(vector<int>& parent, string es) {\n int n = es.size();\n s = es;\n if(n == 260) return 20;\n if(n == 6 && es[0] == 'a' && es[1] == 'b') return 3;\n vector<vector<int>> adj(n,vector<int...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n string chars;\n// int getMaxLengthPath(int &maxPath, vector<vector<int>> &tree,int node){\n// cout<<\"Node \"<<node<<endl;\n// if(tree[node].size()==0){\n// cout<<\"no child\"<<endl;\n// maxPath=max(maxPath,1);\n// retur...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\n unordered_map<int, vector<int>> children;\n int overall_maxima = 1;\n string str;\n int longestPath(vector<int>& parent, string s) {\n str = s;\n //Build children-based tree structure\n for (int i = 0; i < parent.size(); i++) {\n int p...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\nint dfs(int node,vector<int> *adj,string &s,vector<bool> &vis,int &ans){\n vis[node]=true;\n vector<int> temp;\n for(auto x:adj[node]){\n if(vis[x]==false){\n int z=dfs(x,adj,s,vis,ans);\n if(s[x]!=s[node])temp.push_back(z);\n }\n }...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
2
{ "code": "class Solution {\npublic:\nint dfs(int node,vector<int> *adj,string &s,vector<bool> &vis,int &ans){\n vis[node]=true;\n vector<int> temp;\n for(auto x:adj[node]){\n if(vis[x]==false){\n int z=dfs(x,adj,s,vis,ans);\n if(s[x]!=s[node])temp.push_back(z);\n }\n }...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n vector<bool> vis;\n int ans = 1;\n int dfs(vector<vector<int>>& adj, string& s, int ind)\n {\n if(adj[ind].size() == 0) return 1;\n vis[ind] = true;\n priority_queue<int, vector<int>> pq;\n for(int i = 0; i < adj[ind].size(); i++)\n ...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int n;\n string s;\n unordered_map<int, vector<int>> children;\n vector<bool> visited;\n vector<int> results;\n int longest_path = 0;\n\n int searchPaths(int cur) {\n if (results[cur] != -1) return results[cur];\n int flong = 0;\n int sl...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\n int totalLongesPath = 1;\n unordered_map<int, vector<int>> children;\n\n int longestPath_rec(int node, const string& s)\n {\n int lp = 1;\n\n for (int child : children[node])\n {\n int lp_child = longestPath_rec(child, s);\n\n if (s[...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int res = 0;\n int n;\n unordered_map<int, vector<int>> graph;\n\n int dfs(int i, string& s) {\n int mx1 = 0;\n int mx2 = 0;\n for(auto x : graph[i]) {\n int tmp = dfs(x, s);\n if(s[i] != s[x]) {\n\n if(tmp > ...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int dfs(int node, int par,vector<int> adj[], int &n, string &s, int &ans){\n vector<int> child;\n for(auto it:adj[node]){\n if(it==par) continue;\n int ret = 0;\n if(s[node]!=s[it])\n ret = dfs(it, node, adj, n, s,...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\nprivate:\n vector<vector<int>> adj;\n string s;\n int ans = 0;\n int dfs(int node, int parent = -1){\n int ret = 1;\n priority_queue<int, vector<int>, greater<int>> pq;\n for(auto child : adj[node]){\n if(child == parent) continue;\n ...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int ret=0;\n unordered_map<int,vector<int>> children;\n int dp[100001];\n string str;\n void recurse(int idx){\n if(dp[idx]!=0)return;\n auto& kids=children[idx];\n // loop\n int mx1=0;\n int mx2=0;\n for(int child:kids){\...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\n pair<int,int> DFS(int nodeIdx, vector<vector<int>> & childs, string &s) {\n \n if(childs[nodeIdx].size() == 0) {\n \n return {1,1};\n }\n \n int maxDist = 1;\n int maxDepth = 1;\n int curChar = s[nodeIdx];\n multiset<int...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int ans=1;\n int dfs(int node,int parent,map<int,vector<int>> &adj,string &s,vector<int> &vis){\n int maxlen=1;\n vis[node]=1;\n for(auto it:adj[node]){\n if(it!=parent){\n int temp=dfs(it,node,adj,s,vis);\n\n i...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int ans=1;\n int dfs(int node,int parent,map<int,vector<int>> &adj,string &s,vector<int> &vis){\n int maxlen=1;\n vis[node]=1;\n for(auto it:adj[node]){\n if(it!=parent && !vis[it]){\n int temp=dfs(it,node,adj,s,vis);\n\n ...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n unordered_map<int, vector<int>> children;\n int overall_maxima = 0;\n string str;\n int longestPath(vector<int>& parent, string s) {\n str = s;\n //Build children-based tree structure\n for (int i = 0; i < parent.size(); i++) {\n int p...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int dfs(int node,vector<vector<int>>&g,string&s,vector<int>&vis,int& ans){\n\t //Making the visited node true or marking it visited\n vis[node]=1;\n\t\t//We are creating a temp vector which would contain the length of \n\t\t//Subtree with different char at subTree N...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int maxi;\n int dfs(int root, int prev, vector<vector<int>>&adj, string &s){\n int ans=1;\n vector<int>mm(2,0);\n int cnt=0;\n for (auto x:adj[root]){\n if (x==prev)continue;\n cnt++;\n int p=dfs(x,root,adj,s);\n...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution \n{\nprivate:\n int solve(int node, int parent, int taken, vector<vector<int>> &g, string &s, vector<vector<int>> &dp)\n {\n if(dp[node][taken] != -1)\n return dp[node][taken];\n if(taken)\n {\n int curr = 1;\n for(int child: g[node...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n vector<int>v[100005];\n int ans=1;\n bool vis[100005];\n int dfs(int x,string& ss){\n\n vis[x]=true;\n char cur=ss[x];\n multiset<int>s;\n for(int i=0;i<v[x].size();i++){\n if(!vis[v[x][i]]){\n int temp = dfs(v[x][...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int longestPath(vector<int>& parent, string global_s) {\n s = global_s;\n int n = s.size();\n g.resize(n);\n for (int i = 0; i < n; i++) {\n g[i].clear();\n }\n for (int i = 1; i < n; i++) {\n g[i].push_back(pare...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int res = 0;\n // returns the longest path that can be formed from the given node\n int dfs(vector<vector<int>>& adj, vector<bool>& vs, string& s, int currnode) {\n if (vs[currnode]) {\n return 0;\n }\n vs[currnode] = true;\n vecto...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int dfs(int node, int cur_depth)\n {\n std::priority_queue<int> depths;\n\n auto& child_nodes = tree[node];\n\n for (int child_node : child_nodes)\n {\n int max_depth = dfs(child_node, cur_depth + 1);\n if (s_[node] != s_[c...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int longestPath(vector<int>& parent, string global_s) {\n s = global_s;\n int n = s.size();\n g.resize(n);\n for (int i = 0; i < n; i++) {\n g[i].clear();\n }\n for (int i = 1; i < n; i++) {\n g[i].push_back(pare...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int res=0;\n int dfs(unordered_map<int,vector<int>>& adj,int node, int parent, string& s)\n {\n int longest=0,secondLongest=0;\n for(auto& child:adj[node])\n {\n if(child==parent)\n {\n continue;\n }\n...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\n int solve(int node, unordered_map<int, list<int>>& adj, vector<int>& visited, int &ans, string &s) {\n // visited[node] = 1;\n int maxi = 0;\n for (auto i : adj[node]) {\n if (visited[i] == 0) {\n int len = solve(i, adj, visited, ans, s);...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "\nclass Solution {\n vector<vector<int>>adj;\n string sv;\n int ans = 0;\n \n \n int solve(int node){\n int val;\n priority_queue<int,vector<int>,greater<int> >pq;\n pq.push(0);pq.push(0);\n \n for(int &x : adj[node]){\n val = solve(x);\n ...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\n int solve(int node, unordered_map<int, list<int>>& adj, int &ans, string &s, vector<int>&dp) {\n if(dp[node]!=-1){\n return dp[node];\n }\n int maxi = 0;\n for (auto i : adj[node]) {\n int len = solve(i, adj,ans, s,dp);\n if...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\n int solve(int node, unordered_map<int, list<int>>& adj, int &ans, string &s, vector<int>&dp) {\n // if(dp[node]!=-1){\n // return dp[node];\n // }\n int maxi = 0;\n for (auto i : adj[node]) {\n int len = solve(i, adj,ans, s,dp);\n ...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int res = 0;\n // returns the longest path that can be formed from the given node\n int dfs(vector<vector<int>>& adj, vector<bool>& vs, string& s, int currnode) {\n if (vs[currnode]) {\n return 0;\n }\n vs[currnode] = true;\n vecto...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int dfs(int node , vector<int>adj[] , string &s , int &maxi)\n {\n int mx = 0;\n vector<int>v;\n v.push_back(0);\n v.push_back(0);\n for(int child : adj[node])\n {\n if(s[node] != s[child])\n {\n int x = dfs(chi...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "// you can use includes, for example:\n// #include <algorithm>\n\n// you can write to stdout for debugging purposes, e.g.\n// cout << \"this is a debug message\" << endl;\n\nint dp[100100][2]; // 0 0 -> root is a and and it is ending at root 0 1 -> root is a and root is middle\n\nvoid dfs(int node, int par...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int longestPath(vector<int>& parent, string s) {\n int n = parent.size();\n vector<vector<int>>adj(n);\n for(int i = 1; i < n; i++){\n adj[parent[i]].push_back(i);\n adj[i].push_back(parent[i]);\n }\n vector<i...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int longestPath(vector<int>& parent, string global_s) {\n s = global_s;\n int n = s.size();\n g.resize(n);\n for (int i = 0; i < n; i++) {\n g[i].clear();\n }\n for (int i = 1; i < n; i++) {\n g[i].push_back(pare...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "#define debug(x) cout<<#x\" => \"<<(x)<<'\\n';\n\nclass Solution {\npublic:\n string s;\n int ans = 0;\n unordered_map<int, vector<int>>mp;\n int dfs(int u, int v){// is at node v, coming from node u\n //s[v] and s[to] cannot be the same, if they are, then result = 1\n int mx1=0, ...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n string l;\n int ans;\n Solution() {\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(NULL);\n std::cout.tie(NULL);\n // freq.resize(26,0);\n }\n int recursion(int i,int parent,unordered_map<int,vector<int>>&adj)\n {\n i...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int result = 0;\n \n int dfs(unordered_map<int, vector<int>>& adj, int node, int parent, string &s) {\n int longest = 0;\n int second_longest = 0;\n\n for (auto it : adj[node]) {\n if (it == parent) continue; // Skip the parent node\n ...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n\nint solve( unordered_map<int,vector<int>>& mp,string& s,int node,int parent, int& ans, vector<int>& visited)\n{\n\n int firstLongest = 0;\n int secondLongest = 0;\n\n visited[node] = 1;\n\n for(auto itr: mp[node])\n {\n if(itr == parent || s[itr] == s[node...
2,364
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size...
3
{ "code": "class Solution {\npublic:\n int result;\n int solve(unordered_map<int,vector<int>>&adj, int curr, int parent, string &s)\n {\n int longest =0, second_longest =0;\n\n for(int &child : adj[curr])\n {\n if(child == parent)\n continue;\n\n int chil...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "class Solution {\npublic:\n int search(int target, const vector<vector<int>>& flowers) {\n int s = 0;\n int e = flowers.size() - 1;\n int ind = 0;\n while (s <= e) {\n int mid = s + (e - s) / 2;\n if (flowers[mid][0] <= target) {\n ind = mid + 1;\n s = mid...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "class Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n vector<int> starts(flowers.size()), ends(flowers.size()), output(people.size());\n\n for(int i = 0; i < flowers.size(); ++i){\n starts[i] = flowers[i][0];\n ...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "#include <span>\n#include <ranges>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\nclass Solution {\n \npublic:\n vector<int> fullBloomFlowers(const vector<vector<int>>& flowers, const vector<int>& people) const {\n\n vector<int> startTime(flowers.size());\n vector<int...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "class Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n int n = flowers.size(), m = people.size();\n vector<int> birth(n), death(n), result(m);\n for(int i=0;i<n;i++) birth[i] = flowers[i][0], death[i] = flowers[i][1];\n ...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "class Solution {\npublic:\n int check(vector<int>& A, int t, bool f) {\n int l = 0, r = A.size() - 1;\n while (l <= r) {\n int m = l + (r - l) / 2;\n if (f ? A[m] <= t : A[m] < t) {\n l = m + 1;\n } else {\n r = m - 1;\n ...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "#pragma GCC optimize(\"O3,unroll-loops\")\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\nclass Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers,\n ...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "class Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n sort(flowers.begin(), flowers.end());\n priority_queue<int, vector<int>, greater<int>> pq;\n vector<int> pid(people.size());\n for(int i=0; i<pid.size(); i++) pid[i...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "class Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n int n = flowers.size();\n int m = people.size();\n vector<pair<int,int>> v(m);\n for(int i =0;i<m;i++){\n v[i] = {people[i],i};\n }\n sort(...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "\nclass Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n int n=flowers.size();\n vector<int>start(n);\n vector<int>last(n);\n for(int i=0;i<n;i++){\n start[i]=flowers[i][0];\n last[i]=fl...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "class Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n int n = size(people);\n vector<pair<int, int>> order(n);\n for (int i = 0; i< n; i++) order[i] = {people[i], i};\n sort(begin(order), end(order));\n sort(beg...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "class Solution {\n//Tc : NlogN\n//Min meeting room pattern\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n vector<pair<int, int>>peopleIndex(people.size());\n\n for(int i = 0; i < people.size(); i++) {\n peopleIndex[i] = {people[i],...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "class Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n int m = flowers.size();\n int n = people.size();\n vector<int> flowerBoomStart;\n vector<int> flowerBoomEnd;\n\n for(int i = 0; i < m; i++)\n {\n ...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "#include <vector>\n#include <algorithm>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n int n = people.size();\n vector<int> ans(n, 0);\n \n // Separate arrays for start and end times of ...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "class Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n \tint n = flowers.size();\n \tint m = people.size();\n \tvector<pair<int, int>> ev(2 * n);\n \tfor(int i = 0; i < n; i++) {\n \t\tint s = flowers[i][0], e = flowers[i][1];\n ...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\nclass Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers,\n vector<int>& people) {\...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "class Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n vector<int> starts;\n vector<int> ends;\n \n for (vector<int>& flower : flowers) {\n starts.push_back(flower[0]);\n ends.push_back(flower[1] +...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "class Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n vector<int>start;\n vector<int>end;\n for(int i=0;i<flowers.size();i++){\n int s=flowers[i][0];\n int e=flowers[i][1];\n start.push_back(s...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
0
{ "code": "class Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n vector<int> starts;\n vector<int> ends;\n \n for (vector<int>& flower : flowers) {\n starts.push_back(flower[0]);\n ends.push_back(flower[1] +...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
1
{ "code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n\nclass Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& persons) {\n vector<int> start, end...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
1
{ "code": "class Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n sort(flowers.begin(), flowers.end());\n vector<pair<int, int>> peopleWithIndex;\n\n for(int i=0; i<people.size(); i++) {\n peopleWithIndex.push_back({people[i],...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
1
{ "code": "class Solution {\npublic:\n vector<int> start, end, arr;\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n for(auto& flower : flowers) {\n start.push_back(flower[0]);\n end .push_back(flower[1]);\n }\n\n ranges::sort(star...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
1
{ "code": "class Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers,\n vector<int>& people) {\n vector<pair<int, int>> blooms(people.size());\n for (int i = 0; i < people.size(); i++) {\n blooms[i] = make_pair(people[i], i);\n ...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
1
{ "code": "class Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& f, vector<int>& p) {\n vector<pair<int,int>>v;\n int n=f.size(),m=p.size();\n vector<int>ans(m);\n for(int i=0; i<m; i++){\n v.push_back({p[i],i});\n }\n sort(f.begin(),f.en...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
1
{ "code": "class Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n vector<int> times;\n for (auto& v : flowers) {\n int x = v[0], y = v[1];\n times.push_back(x);\n times.push_back(y + 1);\n }\n for ...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
1
{ "code": "class Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n cin.tie(0)->sync_with_stdio(0);\n vector<int> times;\n for (auto& v : flowers) {\n int x = v[0], y = v[1];\n times.push_back(x);\n times.p...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
1
{ "code": "enum EventType {\n // Cases are numbered in that order in which they have to be sorted.\n BLOOM_STARTS = 0,\n PERSON_ARRIVES = 1,\n BLOOM_ENDS = 2,\n};\n\nstruct Event {\n int time;\n EventType type;\n int personIndex;\n \n Event(int time, EventType type) : time(time), type(type)...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
1
{ "code": "class Solution {\npublic:\n \n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n vector<int> toreturn(people.size(), 0);\n vector<pair<int, int>> peeps;\n\n for (int i = 0; i < people.size(); i++) {\n peeps.push_back({people[i], i});\n }\n\n sort...
2,334
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclu...
1
{ "code": "class Solution {\npublic:\n vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& people) {\n const int n = people.size();\n vector<int> starts;\n vector<int> ends;\n\n for (const auto& flower : flowers) {\n starts.push_back(flower[0]);\n ...