id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n = (int)edges.size();\n int maxi = -1;\n for(int i=0;i<n;i++){\n maxi = max({maxi,edges[i][0],edges[i][1]});\n }\n vector<int>hash(maxi+1);\n for(int i=0;i<n;i++){\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n = edges.size();\n vector<int>totalEdges(n+2,0);\n\n for(int i=0;i<n;i++){\n\n totalEdges[edges[i][0]]++;\n totalEdges[edges[i][1]]++;\n }\n\n for(int i=1;i<=n+2;i++){... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n bitset<100000> visited=0;\n for(auto e: edges)\n {\n int u = e[0];\n int v = e[1];\n if(visited[u])\n return u;\n if(visited[v])\n return v;\n... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n vector<int>v(2*edges.size()+1,0);\n for(int i=0;i<edges.size();i++){\n \n v[(edges[i])[0]]+=1;\n v[(edges[i])[1]]+=1;\n }\n int m =0;\n for(int i=0;i<v.size();i+... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) \n {\n vector<int> mp(2*edges.size()+1, 0);\n\n for(int i = 0; i < edges.size(); i++)\n {\n for(int j=0; j<2; j++)\n {\n mp[edges[i][j]]++;\n }\n }\n\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n vector<int> arr(edges.size()*2);\n int k=0;\n for(int i=0;i<edges.size();i++){\n for(int j=0;j<2;j++){\n arr[k]=edges[i][j];\n k++;\n }\n } \n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "#include <vector>\n\nclass Solution {\npublic:\n int findCenter(std::vector<std::vector<int>>& edges) {\n int n = edges.size()+1;\n vector<int> inDegree(n + 1, 0);\n vector<int> outDegree(n + 1, 0);\n\n for (const auto& edge : edges) {\n outDegree[edge[0]]++;\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n vector<int> arr;\n for (int i=0; i<edges.size()+1; ++i) {\n arr.push_back(0);\n }\n\n for (int i=0; i<edges.size(); ++i) {\n for (int j=0; j<2; ++j) {\n\n if (arr[e... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n = edges.size() + 1;\n vector<int> edge[n+1];\n for(int i=0;i<2;i++)\n {\n int u = edges[i][0];\n int v = edges[i][1];\n\n if(i==0)\n {\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n vector<int> arr;\n for (int i=0; i<edges.size()+1; ++i) {\n arr.push_back(0);\n }\n\n for (int i=0; i<edges.size(); ++i) {\n for (int j=0; j<2; ++j) {\n for (int a=... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n = edges.size();\n n++;\n vector<int> adj[n+1];\n for(auto it:edges)\n {\n adj[it[0]].push_back(it[1]);\n adj[it[1]].push_back(it[0]);\n if(adj[it[0]].size(... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n=edges.size()+1;\n vector<vector<int>>v(2,vector<int>(n+1,0));\n for(int i=0;i<edges.size();i++)\n {\n v[0][edges[i][0]]++;\n v[1][edges[i][1]]++;\n }\n for(in... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n vector<int> ans;\n for(int i=0 ; i<edges.size() ; i++){\n ans.push_back(edges[i][0]);\n ans.push_back(edges[i][1]);\n }\n int x;\n sort(ans.begin() , ans.end());\n f... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n=edges.size()+1;\n vector<int> v[n];\n int i;\n vector<int> indegree(n+1,0);\n vector<int> outdegree(n+1,0);\n for(const auto &vect:edges)\n {\n int a=vect[0];\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "#include<vector>\n#include<algorithm>\nclass Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n vector<int> arr;\n for(int i=0;i<edges.size();i++){\n arr.push_back(edges[i][0]);\n arr.push_back(edges[i][1]);\n } \n for(int i=0;i<2;i++)... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "#include<vector>\n#include<algorithm>\nclass Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n vector<int> arr;\n for(int i=0;i<edges.size();i++){\n arr.insert(arr.end(),edges[i].begin(),edges[i].end());\n } \n for(int i=0;i<2;i++){\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n vector<int> adj[edges.size()*2]; \n for(auto v: edges) {\n adj[v[0]].push_back(v[1]);\n adj[v[1]].push_back(v[0]);\n if(adj[v[0]].size() > 1) {\n retur... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n \n int n = edges.size();\n vector<int> indeg(n+1);\n\n for(int i=0;i<n;i++)\n {\n indeg[edges[i][0]-1]++;\n indeg[edges[i][1]-1]++;\n }\n\n vector<pair<int, i... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int maxno=0;\n map<int,int> mpp;\n int n=edges.size();\n int num;\n for(int i=0; i<n; i++){\n for(int j=0; j<2; j++){\n mpp[edges[i][j]]++;\n if(mpp[edge... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\nint count(vector<int>v,int x){\n int c=0;\n for(int i=0;i<v.size();i++){\n if(v[i]==x)\n c++;\n }\n return c;\n}\n int findCenter(vector<vector<int>>& edges) {\n vector<int>v;\n for(int i=0;i<edges.size();i++){\n for(int j=0;j<e... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n vector<bool> visited(1000000);\n for(auto e: edges) {\n int v = e[0], w = e[1];\n if(visited[v]) return v;\n if(visited[w]) return w;\n visited[v]=visited[w] = true;\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n\n vector<int> firstSubVector = edges[0];\n int n=firstSubVector[0];\n int m = firstSubVector[1];\n\n int count_m=0;\n int count_n=0;\n for (auto it:edges)\n {\n if(it[0]... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int condidate1 =edges[0][0] ,condidate2 = edges[0][1];\n int nbC1 = 0 , nbC2 = 0;\n for(auto u: edges){\n if((u[0] == condidate1 ) || (u[1]==condidate1)){\n nbC1 ++;\n }\n... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int one=edges[0][0],second=edges[0][1];\n int c1=0,c2=0;\n\n for(auto i:edges)\n {\n if(i[0]==one || i[1]==one)c1++;\n else if (i[1]==second || i[0]==one)c2++;\n }\n\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n //n*(n+1)/2-(n-1)*k=S\n // get n (len edges+1)\n unsigned long long n=edges.size()+1;\n // get S, su of all the values\n unsigned long long S=0;\n for(auto e: edges){\n S+=... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n //n*(n+1)/2-(n-1)*k=S\n // get n (len edges+1)\n unsigned long n=edges.size()+1;\n // get S, su of all the values\n unsigned long S=0;\n for(auto e: edges){\n S+=e[0];\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n = edges.size();\n n++;\n vector<int>deg(n,0);\n\n for(auto it:edges){\n int u = it[0]-1;\n int v = it[1]-1;\n deg[u]++;\n deg[v]++;\n if(deg... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n vector<int> degree(edges.size()+2,0);\n for(auto i:edges)\n {\n degree[i[0]]++;\n degree[i[1]]++;\n } \n int ans=0;\n for(int i=0;i<edges.size()+2;i++)\n {\n if(d... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n = edges.size();\n vector<int> cnt(n+1, 0);\n for(auto i: edges) {\n cnt[i[1]-1]++;\n cnt[i[0]-1]++;\n }\n for(int i = 0; i <= n; i++) {\n if(cnt[i] == n) {... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n=edges.size();\n vector<int>In(n+2),Out(n+2);\n\n for(auto it:edges){\n In[it[0]]+=1;\n In[it[1]]+=1;\n // Out[it[0]]+=1;\n // Out[it[1]]+=1;\n }\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n\n int base = 10;\n int exponent = 5;\n long max_size = pow(base,exponent);\n std::vector<int> matrix[max_size+1];\n\n int v = 0;\n int e = 0;\n int max_edges = 0;\n int max_... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n = edges.size();\n vector<int> adjList[n+2];\n for(int i = 0; i < n; i++){\n int u = edges[i][0];\n int v = edges[i][1];\n adjList[u].push_back(v);\n adjList[v... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n = edges.size()+1;\n vector<int> adj[n+1];\n for(int i=0;i<edges.size();i++)\n {\n int a = edges[i][0];\n int b = edges[i][1];\n\n adj[a].push_back(b);\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int edgesLen = edges.size();\n vector<int> adj[edgesLen+2];\n\n for(int i = 0; i < edgesLen; i++){\n adj[edges[i][0]].push_back(edges[i][1]);\n adj[edges[i][1]].push_back(edges[i][0]);\n... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n vector<int> adj[edges.size()+1];\n for(int i=0;i<edges.size();i++){\n adj[edges[i][0]-1].push_back(edges[i][1]-1);\n adj[edges[i][1]-1].push_back(edges[i][0]-1);\n }\n int ans;\... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n \n unordered_map<int,int> mp;\n\n for(int i = 0; i < edges.size(); ++i){\n mp[edges[i][0]]++;\n mp[edges[i][1]]++;\n }\n\n for(const auto& x : mp){\n if(x.second == edge... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n=edges.size();\n unordered_map<int,int>m;\n for(int i=0;i<n;i++){\n m[edges[i][0]]++;\n m[edges[i][1]]++;\n }\n int res;\n int count=INT_MIN;\n for(auto ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "\n\nclass Solution {\npublic:\n int findCenter(std::vector<std::vector<int>>& edges) {\n std::unordered_map<int, int> counter;\n\n for (const auto& edge : edges) {\n counter[edge[0]]++;\n counter[edge[1]]++;\n }\n\n for (const auto& [key, value] : counte... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n unordered_map<int,int>map;\n for(int i=0; i<edges.size(); i++){\n map[edges[i][0]]++;\n map[edges[i][1]]++;\n }\n int count=0;\n for(auto el: map){\n if(el.secon... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n unordered_map<int,int> mp;\n for(int i=0;i<edges.size();i++){\n mp[edges[i][0]]++;\n mp[edges[i][1]]++;\n }\n int mxr=0;\n int mxv=0;\n for(auto x: mp){\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "\n\nclass Solution {\npublic:\n int findCenter(std::vector<std::vector<int>>& edges) {\n std::unordered_map<int, int> counter;\n\n for (const auto& edge : edges) {\n counter[edge[0]]++;\n counter[edge[1]]++;\n }\n\n for (const auto& [key, value] : counte... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n unordered_map<int, int> mapa;\n\n for (int i=0; i<edges.size(); ++i){\n int x = edges[i][0];\n int y = edges[i][1];\n\n mapa[x]++;\n mapa[y]++;\n }\n\n fo... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n=edges.size();\n unordered_map<int,int>mp;\n for(int i=0;i<edges.size();i++){\n mp[edges[i][0]]++;\n mp[edges[i][1]]++;\n }\n for(auto it:mp){\n if(it.secon... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "vector<vector<int>> g;\nclass Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n g.clear();\n int n = edges.size();\n g.resize(n+2);\n for(int i=0; i<n; i++){\n g[edges[i][0]].push_back(edges[i][1]);\n g[edges[i][1]].push_back(edges[i][... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "int findMax(vector<vector<int>> mat)\n{\n \n // Initializing max element as INT_MIN\n int maxElement = INT_MIN;\n \n // checking each element of matrix\n // if it is greater than maxElement,\n // update maxElement\n for (int i = 0; i < mat.size(); i++) {\n for (int j = 0; j < 2; j+... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution \n{\npublic:\n int findCenter(vector<vector<int>>& edges) \n {\n int n = edges.size()+1;\n \n vector<int> indeg(n+2,0);\n vector<int> outdeg(n+2,0);\n\n vector<int> adj[n+2];\n\n for(auto &vals:edges)\n {\n adj[vals[0]].push_b... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n map<int,int>mpp;\n for(int i =0 ;i<edges.size();i++){\n mpp[edges[i][0]]++;\n mpp[edges[i][1]]++;\n\n }\n int nodes = 0 ;\n for(auto it:mpp){\n nodes++;\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n map<int,int> mp;\n for(int i=0;i<edges.size();i++)\n {\n for(int j=0;j<edges[i].size();j++)\n {\n mp[edges[i][j]]++;\n }\n }\n int ans=0;\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n map<int, int> m;\n for(int i=0;i<edges.size();i++){\n m[edges[i][0]]++;\n m[edges[i][1]]++;\n }\n for(auto it = m.begin();it!=m.end();it++){\n if(it->second == edges.si... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int ans = -1;\n map<int,int>mp;\n int n = edges.size();\n int m = edges[0].size();\n for(int i =0;i<n;i++){\n for(int j =0;j<m;j++){\n mp[edges[i][j]]++;\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& e) {\n map<int,int>m;\n int n = e.size();\n for(int i = 0; i < n; i ++){\n\n m[e[i][0]]++;\n m[e[i][1]]++;\n\n }\n for(int i = 0; i < n; i ++){\n\n if(m[e[i][0]] == n)retur... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n = edges.size()+1;\n vector<int>in(n+1,0);\n vector<int>adj[n+1];\n for(auto &i : edges)\n {\n in[i[0]]++;\n in[i[1]]++;\n adj[i[0]].push_back(i[1]);\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n \n int n = edges.size()+1;\n vector<vector<int>> adj(n+1);\n vector<int> indeg(n+1, 0);\n for(int i=0; i<edges.size(); i++){\n int u = edges[i][0];\n int v = edges[i][1];\n... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int numVertices = edges.size() + 1; \n vector<vector<int>> adj(numVertices + 1); \n \n for (int i = 0; i < edges.size(); i++) {\n int u = edges[i][0]; \n int v = edges[i][1]; \n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n = 1;\n for (auto edge: edges) {\n n = max(n, max(edge[0], edge[1]));\n }\n auto points = vector<int>(n + 1, 0);\n for (auto edge: edges) {\n points[edge[0]]++;\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n = edges.size()+1;\n vector<vector<int>> adj(n+1);\n vector<int> vis(n+1,0);\n for(int i=0;i<edges.size();i++){\n int u = edges[i][0];\n int v = edges[i][1];\n adj... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& e) {\n\n vector<int>v;\n for(int i=0;i<e.size();i++)\n {\n for(int j=0;j<e[i].size();j++)\n {\n v.push_back(e[i][j]);\n }\n }\n map<int,int>m;\n for(a... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n = edges.size(); \n vector<vector<int>>g(n+2);\n for(auto& it : edges){\n g[it[0]].push_back(it[1]); \n g[it[1]].push_back(it[0]);\n }\n int node = 0;\n for(au... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n = edges.size() + 1; \n vector<vector<int>> ans(n+1);\n for(int i=0;i<edges.size();i++){\n int v=edges[i][0];\n int u=edges[i][1];\n\n ans[u].push_back(v);\n a... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int maxnode=-1;\n for(auto &it:edges)\n {\n maxnode=max(maxnode,max(it[0],it[1]));\n }\n vector<vector<int>> final(maxnode+1);\n for(int i=0;i<edges.size();i++)\n {\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int n = edges.size()+1;\n vector<int> adj_list[n+1];\n for(auto it:edges)\n {\n adj_list[it[0]].push_back(it[1]);\n adj_list[it[1]].push_back(it[0]);\n }\n \n for... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n unordered_map<int,int> mpp;\n for (auto it:edges)\n {\n for (int num : it) {\n mpp[num]++; \n }\n }\n\n int n=edges.size();\n int val=0;\n for... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n int m=edges.size();\n int n=2*edges.size();\n /*vector<int>li(n,0);\n for(auto i:edges){\n li[i[0]]++;\n li[i[1]]++;\n }*/\n map<int,int>mp;\n for(auto i:edge... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n \n map<int, int> answer;\n int maxN=0;\n int remember=-1;\n\n for(auto vec : edges) {\n for(auto e : vec) {\n answer[e]++;\n if(edges.size()==answer[e])... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n map<int, int> mpp;\n int n =edges.size();\n for(auto edge : edges){\n mpp[edge[0]]++;\n mpp[edge[1]]++;\n }\n for(auto mp:mpp){\n if(mp.second == n){\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n unordered_map<int, int> freq;\n for(vector<int> edge : edges) {\n int u = edge[0];\n int v = edge[1];\n if(freq.count(u)) {\n freq[u] += 1;\n }\n ... |
1,916 | <p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</strong> <code>n - 1</code> edges that connect the center node with every other node.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n int findCenter(vector<vector<int>>& edges) {\n\n int n = edges.size();\n \n vector<int> arr(1e5 + 1, 0);\n\n for(int i = 0 ;i<n; i++){\n arr[edges[i][0]]++;\n arr[edges[i][1]]++;\n }\n\n for(int i = 0; i<1e5 + 1;... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 0 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n=nums.size();\n int ans=0, l=k, r=k, mv=nums[k];\n while (l>=0 || r<n) {\n while (l>=0 && nums[l]>=mv) --l;\n while (r<n && nums[r]>=mv) ++r;\n ans=max(ans, mv*(r-l-1));\... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 0 | {
"code": "class Solution {\n /*\n * TWO POINTER APPROACH\n * Ref: https://leetcode.com/problems/maximum-score-of-a-good-subarray/solutions/1108333/java-c-python-two-pointers/\n */\npublic:\n Solution() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 0 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int i=k,j=k;\n int curr_min=nums[k];\n int ans=nums[k],n=nums.size();\n while(i>0||j<n-1){\n int leftvalue=(i>0)?nums[i-1]:0;\n int rightvalue=(j<n-1)?nums[j+1]:0;\n\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 0 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n \n int n=nums.size();\n\n int i=k;\n int j=k;\n int mini=nums[k];\n int left=nums[k];\n int right=nums[k];\n int res=nums[k];\n while(i>0 || j<n-1){\n \n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 0 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int res = nums[k];\n int mini = nums[k];\n int i = k;\n int j = k;\n int n = nums.size();\n\n while (i > 0 || j < n - 1) {\n if (i == 0) {\n j++;\n } ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 0 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size();\n int lo = k;\n int hi = k;\n int ans = nums[k];\n int curMin = nums[k];\n\n while (0 < lo && hi < n - 1) {\n if (nums[lo - 1] < nums[hi + 1]) {\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 0 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int i=k;\n int j=k;\n int currmin =nums[k];\n int ans = nums[k];\n\n int n = nums.size();\n\n while(i>0 ||j<n-1){\n int leftvalue;\n int rightvalue;\n\n i... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 0 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int left = k, right = k;\n \n int min_val = nums[k];\n int max_score = min_val;\n\n while (left > 0 || right < nums.size() - 1) {\n if (left == 0 || nums[right + 1] > nums[left - 1... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 0 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int left = k , right = k;\n int min_val = nums[k];\n int ans = min_val;\n int n = nums.size();\n\n while(left>0 || right < n-1){\n if(left == 0 || (right<n-1 && nums[right+1]>nums[lef... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 0 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size();\n int left = k;\n int right = k;\n int ans = nums[k];\n int currMin = nums[k];\n \n while (left > 0 || right < n - 1) {\n if ((left > 0 ? nums[left ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int res = nums[k];\n\n int left = k, right = k;\n\n int n = nums.size();\n\n int currentMin = nums[k];\n\n while (left > 0 && right < n) {\n res = max(res, (right - left + 1) * curren... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size();\n int left = k;\n int right = k;\n int ans = nums[k];\n int currMin = nums[k];\n \n while (left > 0 || right < n - 1) {\n if ((left > 0 ? nums[left ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\nint calc_score(int i, int j, int min){\n return min*(j-i+1);\n}\nint maximumScore(vector<int>& nums, int k){\n int i, j, min = nums[k], n = nums.size(), score = nums[k];\n min = nums[k];\n int marr[nums.size()];\n for(i = k; i > -1; i--){\n if(nums[i] <= min) { min = nums... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int leftMostGTE[100000] = {0};\n int rightMostGTE[100000] = {0};\n\n int maximumScore(vector<int>& nums, int k) {\n for (int i = 0; i < nums.size(); i++) {\n leftMostGTE[i] = i;\n\n if (i == 0) {\n continue;\n }\n\n... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "#pragma GCC optimize(\"O3\")\n\narray<int, 100001> left1, right1 ;\nclass Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int N = nums.size() ;\n // vector<int> left1(N, -1) ;\n // vector<int> right1(N, N) ;\n\n for(int idx = 0 ; idx < N ; ++idx) {\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& a, int k) {\n\n int n=a.size();\n int mn=a[k],x=1;\n priority_queue<pair<int,pair<int,int>>>q;\n if(k) q.push({a[k-1],{k-1,-1}});\n if(k<n-1) q.push({a[k+1],{k+1,1}});\n\n int ans=a[k];\n while(q.s... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n priority_queue<pair<int,int>> pq;\n if(k-1>=0)pq.push({nums[k-1],k-1});\n if(k+1<nums.size())pq.push({nums[k+1],k+1});\n \n int ans=nums[k],cnt=1,mn=nums[k];\n while(!pq.empty()){\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n\n int n = nums.size();\n\n stack<int> st;\n\n st.push(-1);\n\n int ans = nums[k];\n\n for (int i = 0; i < n; i++) {\n while (st.top() != -1 && nums[st.top()] >= nums[i]) {\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int score = 0;\n int n = nums.size();\n stack<int> st;\n\n for (int i = 0; i <= n; i++) {\n while (!st.empty() && (i == n || nums[st.top()] >= nums[i])) {\n int mn = nums[st.t... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n // finding the largest rectangle of the histogram\n\n // to store index\n stack<int> stk;\n\n // only compute the are when current element is smaller than stk.top()\n // only take the area range... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n // finding the largest rectangle of the histogram\n\n // to store index\n stack<int> stk;\n\n // only compute the are when current element is smaller than stk.top()\n // only take the area range... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size();\n if(!n)\n return 0;\n stack<int>st;\n int ret = 0;\n for(int i = 0;i<=n;i++){\n int val = i==n?-1:nums[i];\n while(!st.empty() && val < num... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& a, int k) {\n int n = a.size();\n int next[n];\n int prev[n];\n stack<int> s;\n int l, idx, ans = -1 ;\n\n // ONE PASS SOLUTION \n\n for(int i=0; i<n; i++) {\n while(!s.empty() && a[s.to... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n stack<int> firstHalf, secondHalf;\n for(int a=0; a<=k; a++){\n while(!firstHalf.empty() && nums[firstHalf.top()] > nums[a])\n firstHalf.pop();\n firstHalf.push(a);\n }\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size();\n\n int minV, score = 0, s;\n vector<pair<int, int>> left;\n \n minV = nums[k];\n for (int i = k - 1; i >= 0; i--) {\n if (nums[i] < minV) {\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& a, int k) {\n int n = a.size();\n int next[n];\n int prev[n];\n stack<int> s;\n int l, idx, ans = -1 ;\n for(int i=0; i<n; i++) {\n while(!s.empty() && a[s.top()] > a[i]){\n idx ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n int ans = 0;\n stack<pair<int, int>> st;\n for(int i=0;i<nums.size();i++){\n int idx = i;\n w... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n int ans = 0;\n stack<pair<int, int>> st;\n for(int i=0;i<nums.size();i++){\n int idx = i;\n w... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n constexpr int padding = 0;\n \n nums.emplace(nums.begin(), padding);\n nums.push_back(padding);\n \n int res = 0;\n stack<size_t> mins;\n mins.push(padding);\n\n ++k;... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int ans = 0;\n stack<pair<int, int>> st;\n for(int i=0;i<nums.size();i++){\n int idx = i;\n while(!st.empty() && st.top().first > nums[i]){\n pair<int, int> val = st.top()... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int>ans(n,1e9);\n ans[k]=nums[k];\n for(int i=k-1;i>=0;i--)\n {\n ans[i]=min(ans[i+1],nums[i]);\n }\n for(int i=k+1;i<n;i++)\n {\n ... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> v(n);\n v[k] = nums[k];\n for(int i = k-1;i>=0;i--){\n v[i] = min(v[i+1],nums[i]);\n }\n for(int i = k+1;i<n;i++){\n v[i] = min(v[... |
1,918 | <p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>
<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <c... | 2 | {
"code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, int k) {\n vector<int> pref(nums.size());\n\n pref[k] = nums[k];\n\n int minEl = nums[k];\n\n for (int i = k - 1; i >= 0; --i) {\n if (nums[i] < minEl)\n minEl = nums[i];\n\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.