id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 1 | {
"code": "class Solution {\r\npublic:\r\n int topoSort(vector<vector<int>>& graph, string colors){\r\n int count = 0;\r\n queue<int> data;\r\n \r\n int n = colors.size();\r\n vector<vector<int>> dp(n, vector<int>(26,0));\r\n \r\n vector<int> indegree(n,0);\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 1 | {
"code": "typedef vector<vector<int>> Graph;\r\n\r\nclass Solution {\r\npublic:\r\n void addDirectedEdge(Graph& g, int u, int v){\r\n g[u].push_back(v);\r\n }\r\n int largestPathValue(string colors,vector<vector<int>>& edges) {\r\n int n = colors.size();\r\n Graph g(n);\r\n vecto... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 1 | {
"code": "class Solution {\r\npublic:\r\n vector<vector<int>>dp;\r\n int f(int node,int col,vector<int>adj[],string &colors)\r\n {\r\n if(dp[node][col]!=-1)\r\n return dp[node][col];\r\n int ans=0;\r\n for(auto it:adj[node])\r\n {\r\n ans=max(ans,f(it,col,adj,co... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 1 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string cs, vector<vector<int>>& edges) {\r\n vector<vector<int>> al(cs.size()), cnt(cs.size(), vector<int>(26));\r\n vector<int> indegrees(cs.size());\r\n for (auto &e: edges) {\r\n al[e[0]].push_back(e[1]);\r\n ++indegrees[e[1]];... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 1 | {
"code": "class Solution {\npublic:\n int largestPathValue(string cs, vector<vector<int>>& edges) {\n vector<vector<int>> al(cs.size()), cnt(cs.size(), vector<int>(26));\n vector<int> indegrees(cs.size());\n for (auto &e: edges) {\n al[e[0]].push_back(e[1]);\n ++indegrees[e[1]];\n }\n v... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 1 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n // build graph do topological sort\r\n int N = colors.size();\r\n vector<list<int>> graph(N);\r\n vector<int> indegree(N, 0);\r\n\r\n for (const auto& e : edges) {\r\n... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 1 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string color, vector<vector<int>>& edges) {\r\n int n = color.size();\r\n int cyc[n];\r\n int visited[n];\r\n vector<int>adj[n];\r\n int dp[n][26];\r\n memset(dp,0,sizeof(dp));\r\n for(auto e: edges) ad... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 1 | {
"code": "class Solution {\r\nprivate:\r\n int clr;\r\n string color;\r\n \r\n unordered_map<char,int> cl;\r\n vector<bool> vis;\r\n vector<int> pathvis;\r\n // vector<vector<int>> graph;\r\n // vector<vector<int>> dp(n,vector<int>(clr,0));\r\n\r\n bool dfs(int parent,vector<vector<int>>& ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 1 | {
"code": "class Solution {\r\nprivate:\r\n int clr;\r\n string color;\r\n \r\n unordered_map<char,int> cl;\r\n vector<bool> vis;\r\n vector<int> pathvis;\r\n // vector<vector<int>> graph;\r\n // vector<vector<int>> dp(n,vector<int>(clr,0));\r\n\r\n bool dfs(int parent,vector<vector<int>>& ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 1 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n int n=colors.size();\r\n vector<int>adj[n];\r\n int ans=0;\r\n vector<int>indegree(n,0);\r\n for(auto it:edges){\r\n adj[it[0]].push_back(it[1]);\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 1 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n int n = colors.size();\r\n vector<int> adj[n];\r\n vector<int> indegree(n,0);\r\n for(auto it: edges){\r\n int u = it[0];\r\n int v = it[1];\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 1 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string s, vector<vector<int>>& e) {\r\n int n=s.size();\r\n vector<int>ad[n];\r\n vector<int>ind(n,0);\r\n for(auto i:e){\r\n ad[i[0]].push_back(i[1]);\r\n ind[i[1]]++;\r\n }\r\n vector<... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 1 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string s, vector<vector<int>>& e) {\r\n int n=s.size();\r\n vector<int>ad[n];\r\n vector<int>ind(n,0);\r\n for(auto i:e){\r\n ad[i[0]].push_back(i[1]);\r\n ind[i[1]]++;\r\n }\r\n vector<... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 2 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n int n = colors.size();\r\n vector<vector<int>> adj(n);\r\n vector<int> in(n, 0);\r\n for (auto e : edges) {\r\n adj[e[0]].push_back(e[1]);\r\n in[e[1]]+... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 2 | {
"code": "class Solution {\r\npublic:\r\n string colors;\r\n vector<vector<int>> adjList;\r\n vector<vector<int>> dp;\r\n vector<int> indegree;\r\n\r\n bool dfs(int node, vector<int>& vis, vector<int>& pathvis) {\r\n vis[node] = 1;\r\n pathvis[node] = 1;\r\n for ( auto ele: adjLis... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 2 | {
"code": "class Solution {\r\npublic:\r\n\r\n int largestPathValue(string colors, vector<vector<int>>& edges) { \r\n int n = colors.size();\r\n\r\n unordered_map<int, list<int>> adj;\r\n vector<int> indegree(n, 0);\r\n vector<int> col(26, 0);\r\n \r\n for(auto edge : edg... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 2 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n int n = colors.length();\r\n vector<int> indegrees(n, 0);\r\n vector<int> visited(n, 0);\r\n vector<vector<int>> graph(n);\r\n vector<vector<int>> colorDp(n, vector<in... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 2 | {
"code": "class Solution {\r\npublic:\r\n int dfs(int i,vector<vector<int>>&graph,vector<int>&vis,vector<vector<int>>&cf,string &colors){\r\n if(vis[i]==1){\r\n return true;\r\n }\r\n if(vis[i]==2){\r\n return false;\r\n }\r\n vis[i]=1;\r\n bool ans=f... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 2 | {
"code": "class Solution {\r\npublic:\r\n map<int,int>in;\r\n queue<int>q;\r\n int largestPathValue(string colors, vector<vector<int>> &edg) {\r\n vector<vector<int>> adj((int)colors.size()+1);\r\n vector<vector<int>>mat((int)colors.size()+1,vector<int>(27));\r\n for (int i = 0; i < col... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int dfs(int node, vector<int> &visited, vector<int> &dfsvisited ,vector<vector<int>> &adj, string &colors, vector<vector<int>> &res)\r\n {\r\n if(dfsvisited[node])\r\n {\r\n return INT_MAX;\r\n }\r\n\r\n if(visited[node])\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n vector<vector<int>> colorVectors;\r\n vector<vector<int>> adj;\r\n void dfs(int node, string &colors){\r\n vector<int> cnt(26);\r\n for(int i : adj[node]){\r\n if(colorVectors[i].size()==0){\r\n dfs(i, colors);\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n bool has_cycle;\r\n\r\n void dfs(int node, int col, string& colors, vector<int>& vis,\r\n vector<vector<int>>& adj, vector<vector<int>>& dp) {\r\n vis[node] = 1; // Mark the node as visited\r\n int same_col = ((colors[node] - 'a') ==\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n bool has_cycle;\r\n\r\n void dfs(int node, int col, string& colors, vector<int>& vis,\r\n vector<vector<int>>& adj, vector<vector<int>>& dp) {\r\n vis[node] = 1; // Mark the node as visited\r\n int same_col = ((colors[node] - 'a') ==\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n map<int, vector<int>> adj;\r\n int n = colors.size();\r\n vector<int> indegree(n, 0);\r\n\r\n for(auto e: edges) {\r\n adj[e[0]].push_back(e[1]);\r\n in... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "int doMax(vector<int> &colors){\r\n int m = -1;\r\n for(int a=0; a<26; a++)\r\n m = max(m, colors[a]);\r\n return m;\r\n}\r\n\r\nvoid computeGraph(vector<vector<int> > &graph, vector<vector<int> > &maxColors, vector<bool> &visited, int node, string &colors){\r\n if(graph[node].empty()){\... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n int n=colors.size();\r\n vector<vector<int>>adj(n),reverse_(n);\r\n vector<int>indegree(n,0);\r\n for(auto it:edges){\r\n adj[it[0]].push_back(it[1]);\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n \r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n int n=colors.size();\r\n vector<int> g[n+1];\r\n vector<int> inDegree(n+1,0);\r\n vector<vector<int>> nodeCol(n+1,vector<int>(27,0));\r\n \r\n\r\n for(a... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n \r\n int n = colors.size();\r\n unordered_map<int,list<int>>adjList;\r\n vector<int>indegree(n , 0);\r\n\r\n for(auto edge : edges){\r\n int u = edge[0];\r\... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n int ans=0;\r\n int count=0;\r\n int n = colors.size();\r\n unordered_map<int , list<int>>adj;\r\n vector<int>indegree(n , 0);\r\n\r\n for(auto i: edges){\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n int n = colors.size();\r\n vector<vector<int>> mp(n);\r\n vector<int> inDeg(n,0);\r\n for(auto it: edges){\r\n mp[it[0]].push_back(it[1]);\r\n if(it[1]=... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n int nodes = colors.size();\r\n \r\n vector<vector<int>> prevcnt (nodes,vector<int>(26,0));\r\n\r\n vector<vector<int>> adj(nodes);\r\n vector<int> indegree(nodes,0);\r... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\nmap<int,vector<int>> mp;\r\nint vi[100010];\r\nint dp[100010][26];\r\nset<int> s;int ok;\r\nstring ch;\r\n void dfs(int node){\r\n\r\n vi[node] = 1;\r\n s.insert(node);\r\n for(auto i : mp[node]){\r\n\r\n if(s.find(i) != s.end()){\r\n ok ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\nmap<int,vector<int>> mp;\r\nint vi[100010];\r\nint dp[100010][26];\r\nset<int> s;int ok;\r\nstring ch;\r\n void dfs(int node){\r\n\r\n vi[node] = 1;\r\n s.insert(node);\r\n for(auto i : mp[node]){\r\n\r\n if(s.find(i) != s.end()){\r\n ok ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n stack<int> st;\r\n bool dfsCycleDG(int node, vector<int> adj[], vector<int> &vis, vector<int> &pathvis, string &colors, vector<vector<int>> &cnt) {\r\n vis[node] = 1;\r\n pathvis[node] = 1;\r\n for(auto it : adj[node]) {\r\n if(vis[it] =... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n stack<int> st;\r\n bool dfsCycleDG(int node, vector<int> adj[], vector<int> &vis, vector<int> &pathvis, string &colors, vector<vector<int>> &cnt) {\r\n vis[node] = 1;\r\n pathvis[node] = 1;\r\n for(auto it : adj[node]) {\r\n if(vis[it] =... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n unordered_map<int, vector<int>> edgs;\r\n int n;\r\n int ans = 1;\r\n vector<vector<int>> dp; // 用來存儲每個節點的顏色計數\r\n\r\n int dfs(int node, string &colors, vector<int> &visited)\r\n {\r\n if (visited[node] == 1) // 發現環\r\n return -1;\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n unordered_map<int, vector<int>> edgs;\r\n int n;\r\n vector<int> visited;\r\n vector<vector<int>> dp;\r\n int ans = 1;\r\n bool dfs(string &colors, int node)\r\n {\r\n if(visited[node] == 1)\r\n {\r\n return false;\r\n }\r... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Graph\r\n{\r\n unordered_map<int, vector<int>> adj;\r\n unordered_map<int, int> indegreeTracker;\r\n vector<vector<int>> nodeToColorFreq;\r\n string colors;\r\npublic:\r\n Graph(string &colors)\r\n {\r\n nodeToColorFreq.resize(colors.size(), vector<int>(26, 0));\r\n th... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\nvector<int>v1;\r\nint maxi=0;\r\nbool isCyclic(int V, vector<int> adj[],string& colors,vector<vector<int>>dp) {\r\n\t\tvector<int>indegree(V,0);\r\n\t\tfor (int i = 0; i < V; i++) {\r\n\t\t\tfor (auto it : adj[i]) {\r\n\t\t\t\tindegree[it]++;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tqu... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n int n = colors.size();\r\n vector<int> ind(n);\r\n vector<vector<int>> adj(n);\r\n for(auto i : edges)\r\n {\r\n adj[i[0]].push_back(i[1]);\r\n }\r\n... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int dfs(int node, string& colors, vector<vector<int>>& adj, vector<vector<int>>& count,\r\n vector<bool>& visit, vector<bool>& inStack) {\r\n // If the node is already in the stack, we have a cycle.\r\n if (inStack[node]) {\r\n return I... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int dfs(int node, string& colors, vector<vector<int>>& adj, vector<vector<int>>& count,\r\n vector<bool>& visit, vector<bool>& inStack) {\r\n // If the node is already in the stack, we have a cycle.\r\n if (inStack[node]) {\r\n return I... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n vector<vector<int>> adj;\r\n vector<vector<int>> adj2;\r\n vector<bool> vis;\r\n vector<int> topo;\r\n void dfs(int i){\r\n vis[i] = true;\r\n for(auto it:adj[i]){\r\n if(!vis[it]){\r\n dfs(it);\r\n }\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n int n = colors.size();\r\n vector<vector<int>> adj(n+1);\r\n for (auto it : edges)\r\n {\r\n adj[it[0]].push_back(it[1]);\r\n }\r\n vector<int> indeg... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n unordered_map<int, vector<int>> hash;\r\n int res = 0;\r\n void dfs(vector<vector<int>>& adj, int& currnode, string& colors, int& pass, vector<bool>& done) {\r\n if(res == -1) return;\r\n if(hash[currnode].size()) {\r\n if(done[currnode]) {\... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n unordered_map<int, vector<int>> dp;\r\n int ans = 0;\r\n void dfs(vector<vector<int>>& adj, int& node, string& colors, int& pass, vector<bool>& vis) {\r\n if(ans == -1) return;\r\n if(dp[node].size()) {\r\n if(vis[node]) {\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int lcv = 0;\r\n bool dfs(int node, unordered_map<int,vector<int>> &adj,string &colors, vector<int> &freq,vector<int> &vis, vector<int> &pathVis,vector<vector<int>> &dp){\r\n vis[node] = 1;\r\n pathVis[node] = 1;\r\n int curColor = colors[node]-'a'... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int lcv = 0;\r\n bool dfs(int node, unordered_map<int,vector<int>> &adj,string &colors, vector<int> &freq,vector<int> &vis, vector<int> &pathVis,vector<vector<int>> &dp){\r\n vis[node] = 1;\r\n pathVis[node] = 1;\r\n int curColor = colors[node]-'a'... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\npublic:\n int res = 0;\n unordered_map<int, vector<int>> dp;\n\n bool isCyclic(int u, vector<int> adj[], vector<bool>& vis, vector<bool>& dfsVis) {\n vis[u] = 1, dfsVis[u] = 1;\n for(auto& v : adj[u]) {\n if(!vis[v]) {\n if(isCyclic(v, adj,... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\npublic:\n int res = 0;\n unordered_map<int, vector<int>> dp;\n\n bool isCyclic(int u, vector<int> adj[], vector<bool>& vis, vector<bool>& dfsVis) {\n vis[u] = 1, dfsVis[u] = 1;\n for(auto& v : adj[u]) {\n if(!vis[v]) {\n if(isCyclic(v, adj,... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int dfs(int node,vector<bool>& vis,vector<bool>& pathvis,vector<vector<int>> &dp,vector<int> adj[],string &colors){\r\n\r\n if(pathvis[node]) return INT_MAX;\r\n if(vis[node]) return 0;\r\n\r\n vis[node] =1;\r\n pathvis[node]=1;\r\n\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\n void dfs(int curr, string &colors, vector<int> adjList[], vector<bool> &visited, vector<bool> &currPath, vector<vector<int>> &count, int &ans) {\r\n if(currPath[curr] || ans == -1) {\r\n ans = -1;\r\n return;\r\n }\r\n if(visited[curr]) ret... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n void recurs(int p, vector<vector<int>>& adj, vector<int>& vis, vector<int>& track, int& ans, string& colors, vector<vector<int>>& store){\r\n if(vis[p]>0 || ans==-1) {\r\n ans = -1;\r\n return;\r\n }\r\n if(vis[p] == -1){\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\n #define pb push_back\r\n vector<int> g[100007];\r\n stack<int> st;\r\n void dfs(int vertex, vector<int>& vis){\r\n vis[vertex]=1;\r\n for(int child : g[vertex]){\r\n if( vis[child]==1) continue;\r\n dfs(child,vis);\r\n }\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n int n = colors.length();\r\n vector<vector<int>> freq(n, vector<int>(26, 0));\r\n done = vector<bool>(n, false);\r\n unordered_map<int, vector<int>> map;\r\n for (int ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n int n = colors.length();\r\n vector<vector<int>> freq(n, vector<int>(26, 0));\r\n done = vector<bool>(n, false);\r\n unordered_map<int, vector<int>> map;\r\n for (int ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n unordered_map<int,vector<int>> mp;\r\n int ans = 0;\r\n void dfs(int node,string& colors,vector<vector<int>>& adj,vector<int>& vis) {\r\n if(ans == -1) return; //cycle \r\n //checking wheather cycle or not\r\n if(mp[node].size()) {\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int maxi = 0;\r\n // vector<int>topoSort(int n,string&col,vector<int>&indeg,vector<int>adj[],map<int,vector<int>>&mp){\r\n // queue<int>q; // node,colorCount\r\n // vector<int>ans;\r\n // for(int i=0;i<n;i++){\r\n // if(indeg[i]==0){\r\n... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n int n = colors.length();\r\n vector<vector<int>> adj(n);\r\n\r\n vector<int> inDegree(n, 0);\r\n for(auto edge: edges){\r\n adj[edge[0]].push_back(edge[1]);\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "\r\nclass Solution {\r\npublic:\r\n int largestPathValue(string colors, vector<vector<int>>& edges) {\r\n\r\n vector<int> ind(colors.size(), 0);\r\n vector<vector<int>> gr(colors.size());\r\n for (int i = 0; i < edges.size(); i++) {\r\n gr[edges[i][0]].push_back(edges[i][... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\n\r\npublic:\r\n\r\n vector<vector<int>> nodecolor;\r\n set<int> visited;\r\n set<int> path;\r\n vector<vector<int>> adjList;\r\n\r\n string c;\r\n \r\n int dfs(int node) {\r\n if (path.count(node)) {\r\n return INT_MAX;\r\n } \r\n if ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\n\r\npublic:\r\n\r\n vector<vector<int>> nodecolor;\r\n set<int> visited;\r\n set<int> path;\r\n vector<vector<int>> adjList;\r\n\r\n string c;\r\n \r\n int dfs(int node) {\r\n if (path.count(node)) {\r\n return INT_MAX;\r\n } \r\n if ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n vector<int> find(vector<vector<int>> &g, int node, vector<bool> &vis, string &colors, vector<vector<int>> &dp){\r\n vector<int> res(26,0);\r\n for(int i =0;i<g[node].size();i++){\r\n int child = g[node][i];\r\n if(!vis[child]){\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "/*\n https://leetcode.com/problems/largest-color-value-in-a-directed-graph/\n \n Core idea is to first process the nodes that come first in terms of dependency order.\n This ensures that when we process a node, all the paths coming to that node have been processed and\n the node will be proc... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\n bool chck(int i, auto &adj, auto &vst1, auto &vst2){\r\n vst1[i]=1;\r\n vst2[i]=1;\r\n int ans=0;\r\n for(auto it:adj[i]){\r\n if(vst1[it]){\r\n if(vst2[it])return 1;\r\n }else{\r\n ans=ans|chck(it,adj,v... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n\r\n int dfs(int node, vector<set<int>> &graph, string &colors, int m, unordered_set<int> &visited, unordered_set<int> &path, vector<vector<int>> &colorMap){\r\n if(path.find(node) != path.end())\r\n return -1;\r\n\r\n if(visited.find(node) != visi... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n int dfs(int node, vector<set<int>> &graph, string &colors, unordered_set<int> &visited, unordered_set<int> &path, vector<vector<int>> &colorMap) {\r\n if (path.find(node) != path.end())\r\n return -1;\r\n\r\n if (visited.find(node) != visited.end(... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n void dfs(int node, vector<int>graph[],vector<int>&vis,vector<vector<int>>&dp,string &colors, bool &val, int &ans){\r\n \r\n if(dp[node][0] != -1)return ;\r\n\r\n vector<int>v(26,0);\r\n\r\n for(int i =0 ; i<26 ; i++){\r\n if(i == (colors[no... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\n\r\npublic:\r\n\r\n map<int, vector<int>> mp;\r\n\r\n map<int, vector<int>> adj;\r\n map<int,int> vis;\r\n\r\n string s;\r\n\r\n vector<int> visited;\r\n\r\n void dfs(int node) {\r\n vis[node] = 1;\r\n\r\n vector<int> v(26, 0);\r\n\r\n for (auto ch... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n vector<vector<int>> dp;\r\n bool dfs(vector<vector<int>> &adj,int ind,vector<bool> &curr,string &s){\r\n\r\n if(dp[ind][0]!=-1){\r\n\r\n return (curr[ind]);\r\n\r\n }\r\n\r\n curr[ind] = true;\r\n\r\n dp[ind]= vector<int> (26,0);\... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n vector<int>dfs(int node,vector<int>adj[],string &colors,int &ans,vector<vector<int> >&dp,vector<int>&vis){\r\n if(vis[node]==1){\r\n return dp[node];\r\n\r\n \r\n }\r\n vector<int>store(26,0);\r\n vis[node]=1;\r\n ... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<int, vector<int>>dp;\n bool isCycle(vector<int> graph[], int src, vector<int>&vis, vector<int>&dfsVis) {\n vis[src] = dfsVis[src] = 1;\n for(auto &adj : graph[src]) {\n if(!vis[adj]) {\n if(isCycle(graph, adj, vis, dfsV... |
1,986 | <p>There is a <strong>directed graph</strong> of <code>n</code> colored nodes and <code>m</code> edges. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a string <code>colors</code> where <code>colors[i]</code> is a lowercase English letter representing the <strong>color</strong... | 3 | {
"code": "class Solution {\r\npublic:\r\n map<int,vector<int>> dp;\r\n vector<int> dfs(int src,auto &adj,auto &st){\r\n vector<int> ans(26,0);\r\n\r\n if(dp.count(src) > 0)return dp[src];\r\n\r\n for(auto i:adj[src]){\r\n auto vv = dfs(i,adj,st);\r\n\r\n for(int k = 0... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 0 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n int n = nums.size();\n int t = (1<<n);\n int xt = 0;\n for(int i = 0;i<t;++i) {\n int x = 0;\n int j = i;\n int k = n-1;\n while(j){\n x ^= (j&1)*num... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 0 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n int n = nums.size();\n int res = 0;\n for(int i = 0 ; i< (1ll << n); i++)\n {\n int curr_res = 0;\n for(int j = 0;j<n;j++)\n {\n if( (i>> j)&1 )\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n vector<int> temp(nums.size());\n int jack = pow(2, nums.size());\n\n for (int i=0; i < nums.size(); i++)\n {\n temp[i] = (1 << i); //each number gets a bit assigned to it.\n cout << \"... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n int all_subset_xor_sum{};\n subsetXORSum(nums, 0, nums.size(), all_subset_xor_sum);\n\n return all_subset_xor_sum;\n }\nprivate:\n void subsetXORSum(vector<int>& nums, int i, int sz, int &all_subset_xor_sum) {... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n vector<int> sums(pow(2, nums.size()), 0);\n for (int i = 0, p = sums.size() >> 1; i < nums.size(); ++i, p >>= 1) {\n int k = 0;\n while (k < sums.size()) {\n for (int j = 0; j < p; ++j,... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n int n = nums.size();\n int ans = 0;\n function<void(int, int)> dfs = [&](int i, int s) {\n if (i >= n) {\n ans += s;\n return;\n }\n dfs(i + 1, s);\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n vector<int> result;\n result.push_back(0);\n int sum = 0;\n for(const int& num : nums){\n int len = result.size();\n for(int i = 0; i < len; i++){\n result.push_back(num ^... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "#pragma GCC optimize (\"O3,unroll-loops\")\n#pragma GCC target (\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nclass Solution {\nprivate:\n vector<int> all;\n int curr = 0;\n\n void helper(const vector<int> &nums, int i) {\n if (i == nums.size()) all.push_back(curr);\n else {\n curr ^... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n\n void printSubset(const deque<int>& nums) {\n for (auto i : nums) {\n cout << i << \" \";\n }\n }\n\n int xorSubset(const deque<int>& nums) {\n int ret = 0;\n for (auto i : nums) {\n ret ^= i;\n }\n return... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n vector<int> record(1, 0);\n for (int& i : nums) {\n vector<int> temp = record;\n record.insert(record.end(), temp.begin(), temp.end());\n for (int j = temp.size() - 1; j >= 0; j--)\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\nvoid f(vector<int>& nums, int i,int x,vector<int>& ans){\n if(i==nums.size()){\n ans.push_back(x);\n return;\n }\n f(nums,i+1,x^nums[i],ans);\n f(nums,i+1,x,ans);\n}\n int subsetXORSum(vector<int>& nums) {\n vector<int>ans;\n int x=0;\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n void sumsub(int n, vector<int>& nums, int xorSum, vector<int>& v) {\n if(n == nums.size()) {\n v.push_back(xorSum);\n return;\n }\n\n sumsub(n + 1, nums, xorSum ^ nums[n], v);\n sumsub(n + 1, nums, xorSum, v);\n }\n\n in... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n void subsets(vector<int> &nums,int i,vector<int> &ans,vector<int> &subset) {\n if(i==nums.size()) {\n int dt=0;\n for(int i=0;i<ans.size();i++) {\n dt^=ans[i];\n }\n subset.push_back(dt);\n cout << e... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n \n void genarate(int idx,vector<int>&sub,vector<int>&nums,vector<int>&v)\n {\n if(nums.size()==idx)\n {\n int ans=0;\n for(int i:sub)\n ans^=i;\n v.push_back(ans);\n return;\n }\n genarate... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n \n void genarate(int idx,vector<int>&sub,vector<int>&nums,vector<int>&v)\n {\n if(nums.size()==idx)\n {\n int ans=0;\n for(int i:sub)\n ans^=i;\n v.push_back(ans);\n return;\n }\n genarate(... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution \n{\npublic:\n int subsetXORSum(vector<int>& nums) \n {\n vector<int> subset;\n subset.reserve(1 << nums.size());\n vector<int> xors;\n xors.reserve(nums.size());\n xorSubsets(nums, 0, subset, xors);\n int s = 0;\n for (int i : xors)\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "#include <numeric>\n\nclass Solution \n{\npublic:\n int subsetXORSum(vector<int>& nums) \n {\n vector<int> subset;\n subset.reserve(1 << nums.size());\n vector<int> xors;\n xors.reserve(nums.size());\n xorSubsets(nums, 0, subset, xors);\n \n return std... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n void generate(vector<int> nums, vector<int>& ans, int idx, int size, int& sum){\n if(idx == size) return;\n generate(nums, ans, idx+1, size, sum);\n if(ans.empty()) ans.push_back(0);\n vector<int> helper;\n int s = ans.size();\n int t... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\nint xorsum(vector<int> temp){\n int n=temp.size();\n if(n==0){\n return 0;\n }\n if(n==1){\n return temp[0];\n }\n int res=temp[0];\n for(int i=1;i<n;i++){\n res^=temp[i];\n }\n return res;\n}\n int subsetXORSum(vector<int>& nums... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n vector<int>v;\n vector<vector<int>>vt;\n int xr=0;\n int total=0;\n travel(nums,xr,total,0,v,vt);\n return total;\n\n }\n void travel(vector<int>& nums,int &xr,int &total,int idx,vector<in... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\nint sol=0;\n int subsetXORSum(vector<int>& nums) {\n xorRec(nums, 0, nums.size(), 0);\n return sol;\n }\n\n void xorRec(vector<int>& nums, const int i, const int n, int res) {\n if (i >= n) {\n sol+= res;\n return;\n }\n... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n vector<int> temp;\n getsubsets(nums, temp, 0, nums.size());\n return sum;\n }\nprivate:\n int sum = 0;\n void getsubsets(vector<int>& nums, vector<int>& temp, int l, int h) {\n if(temp.size())\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int res;\n int xorOfArray(vector<int> arr){\n int xor_arr = 0;\n for (int i = 0; i < arr.size(); i++) {\n xor_arr = xor_arr ^ arr[i];\n }\n return xor_arr;\n }\n void backtrack(vector<int>& nums, int start, vector<int>& track){\... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n void solve( vector<int> arr , int& sum , int XOR , int index ) {\n sum += XOR ;\n for( int i = index ; i < arr.size() ; i++ )\n solve( arr , sum , XOR ^ arr[i] , i + 1 ) ;\n }\n\n int subsetXORSum(vector<int>& nums) {\n int sum = 0 ;\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\nint ans = 0;\npublic:\n int subsetXORSum(vector<int>& nums) {\n vector<int>t;\n int n = nums.size();\n f(n, nums, t, 0);\n return ans;\n }\n void f(int n, vector<int>nums, vector<int>&t, int start){\n int x = 0;\n for(int i=0; i<t.size();... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n\n void calc(int ind,vector<int>& v1,vector<vector<int>>& res,vector<int>& nums,int& sum){\n int n=nums.size();\n int subxor=0;\n for(int i=0;i<v1.size();i++){\n subxor^=v1[i];\n }\n sum+=subxor;\n res.push_back(v1);\n\n\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n void f(int ind,vector<int> &nums,vector<int> &temp,vector<vector<int>> &res)\n {\n if(ind>=nums.size())\n {\n res.push_back(temp);\n return ;\n }\n temp.push_back(nums[ind]);\n f(ind+1,nums,temp,res);\n temp.p... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.