id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class Solution {\npublic:\n\n vector<int>parent;\n void disjoint(int size){\n parent.resize(size+1);\n for(int i=0;i<=size;i++)\n parent[i]=(i);\n }\n int find(int u){\n if(parent[u]==u)return u;\n return parent[u] = find(parent[u]);\n }\n void merge(int... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class Solution {\npublic:\n vector<int>parent;\n void disjoint(int size){\n parent.resize(size+1);\n for(int i=0;i<=size;i++)\n parent[i]=(i);\n }\n int find(int u){\n if(parent[u]==u)return u;\n return parent[u] = find(parent[u]);\n }\n void merge(int u... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class Solution {\nprivate:\n int parent[101];\n int rank[101];\n\n void dsu(int n){\n for(int i=0;i<n;i++){\n parent[i] = i;\n rank[i] = 0;\n }\n }\n\n int findParent(int n){\n if(parent[n] == n)\n return n;\n \n return pare... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class Solution {\nprivate:\n int parent[101];\n int rank[101];\n\n void dsu(int n){\n for(int i=0;i<n;i++){\n parent[i] = i;\n rank[i] = 0;\n }\n }\n\n int findParent(int n){\n if(parent[n] == n)\n return n;\n \n return pare... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class Solution {\nprivate:\n int parent[101];\n int rank[101];\n\n void dsu(int n){\n for(int i=0;i<n;i++){\n parent[i] = i;\n rank[i] = 0;\n }\n }\n\n int findParent(int n){\n if(parent[n] == n)\n return n;\n \n return pare... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "struct union_find {\n // When data[x] < 0, x is a root and -data[x] is its tree size. When data[x] >= 0, data[x] is x's parent.\n vector<int> data;\n int components = 0;\n\n union_find(int n = -1) {\n if (n >= 0)\n init(n);\n }\n\n void init(int n) {\n data.assign... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class Solution {\npublic:\nint findparent(int u,vector<int>&parent)\n{\n if(u==parent[u])\n return u;\n return parent[u]=findparent(parent[u],parent);\n}\nbool union1(int u,int v,vector<int>&parent,vector<int>&rank)\n{\n int pu=findparent(u,parent);\n int pv=findparent(v,parent);\n if(pu==... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class Solution {\npublic:\nint findparent(int u,vector<int>&parent)\n{\n if(u==parent[u])\n return u;\n return parent[u]=findparent(parent[u],parent);\n}\nbool union1(int u,int v,vector<int>&parent,vector<int>&rank)\n{\n int pu=findparent(u,parent);\n int pv=findparent(v,parent);\n if(pu==... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class dsu {\npublic:\n vector<int> p;\n vector<int> s;\n dsu(int n) {\n p.resize(n);\n s.resize(n, 1);\n for (int i = 0; i < n; i++) {\n p[i] = i;\n }\n }\n int parent(int u) {\n if (u == p[u])\n return u;\n return p[u] = parent... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class dsu {\npublic:\n vector<int> p;\n vector<int> s;\n dsu(int n) {\n p.resize(n);\n s.resize(n, 1);\n for (int i = 0; i < n; i++) {\n p[i] = i;\n }\n }\n int parent(int u) {\n if (u == p[u])\n return u;\n return p[u] = parent... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class DisjointSet {\n\npublic:\n vector<int> parent;\n vector<int> Size;\n\n DisjointSet(int n) {\n parent.resize(n, 0);\n Size.resize(n, 1);\n for (int i = 0; i < n; i++)\n parent[i] = i;\n }\n\n void UnionBySize(int u, int v) {\n int pr_u = findUpr(u)... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class DisjointSet{\n private:\n vector<int> parent, rank;\n public:\n DisjointSet(int& size){\n parent.resize(size);\n rank.resize(size, 0);\n\n for(int i = 0; i<size; ++i){\n parent[i] = i;\n }\n }\n\n int findPar... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class DSU{\npublic:\n unordered_map<int,int>p,sz;\n int find(int u){\n if(!p.count(u))p[u]=u,sz[u]=1;\n return u==p[u]?u:(p[u]=find(p[u]));\n }\n bool unite(int x,int y){\n x = find(x);\n y = find(y);\n if(x==y)return false;\n if(sz[x] >sz[y])swap(x,y);... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class Solution {\npublic:\n class DSU {\n public:\n vector<int> par, sz;\n DSU(int n) {\n par.resize(n);\n for(int i=0; i<n; i++) par[i]=i;\n sz.resize(n, 1);\n }\n\n int findPar(int node) {\n ... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class Solution {\npublic:\n class DisjointSet {\n vector<int> rank, parent, size;\npublic:\n DisjointSet(int n) {\n rank.resize(n + 1, 0);\n parent.resize(n + 1);\n size.resize(n + 1);\n for (int i = 0; i <= n; i++) {\n parent[i] = i;\n size[i] = 1... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class Solution {\npublic:\n static bool cmp(vector<int> &f,vector<int> &s){\n return f[2]<s[2];\n }\nvoid makeset(vector<int> &par,vector<int> &rank,int n){\n for(int i=0;i<=n;i++){\n par[i]=i;\n rank[i]=0;\n }\n }\n int findparent(int node,vector<int> &parent){\n if(parent[... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class Solution {\npublic:\n int mst_cost(vector<vector<pair<int,int>>> &g,int a=-1,int b=-1,int w_ab=0){\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;\n int mst = 0;\n int num_edge_mst = 0;\n unordered_set<int> included; \n if... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n\nstruct UnionFindSet {\n\tvector<int> parent;\n\tvoid init(int nn) {\n\t\tparent.resize(nn + 1);\n\t\tfor (int i = 0; i < parent.size(); i++)\n\t\... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n\nstruct UnionFindSet {\n\tvector<int> parent;\n\tvoid init(int nn) {\n\t\tparent.resize(nn + 1);\n\t\tfor (int i = 0; i < parent.size(); i++)\n\t\... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class Solution {\npublic:\n vector<int> parent; \n \n static bool cmp(vector<int>&a , vector<int>&b) {\n return a[2] < b[2]; \n }\n\tvoid union_(int u,int v){\n\t if(abs(parent[u])<abs(parent[v])){\n\t parent[v]+=parent[u];\n\t parent[u]=v;\n\t }\n\t else{\n\t ... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "//JAI SIYA RAM \nclass Solution {\npublic:\n vector<int> parent; \n \n static bool cmp(vector<int>&a , vector<int>&b) {\n return a[2] < b[2]; \n }\n\tvoid union_(int u,int v){\n\t if(abs(parent[u])<abs(parent[v])){\n\t parent[v]+=parent[u];\n\t parent[u]=v;\n\t }\n\t ... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "//JAI SIYA RAM \nclass Solution {\npublic:\n vector<int> parent; \n \n static bool cmp(vector<int>&a , vector<int>&b) {\n return a[2] < b[2]; \n }\n\tvoid union_(int u,int v){\n\t if(abs(parent[u])<abs(parent[v])){\n\t parent[v]+=parent[u];\n\t parent[u]=v;\n\t }\n\t ... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n\nstruct UnionFindSet {\n\tvector<int> parent;\n\tvoid init(int nn) {\n\t\tparent.resize(nn + 1);\n\t\tfor (int i = 0; i < parent.size(); i++)\n\t\... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class Solution {\nprivate:\n int find(int u, vector<int>& parent){\n while(parent[u] >= 0)\n u = parent[u];\n return u;\n }\n int Union(int w, int u, int v, vector<int>& parent){\n int pu = find(u,parent);\n int pv = find(v,parent);\n if(pu != pv){\n ... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class Solution {\npublic:\n int parent[100];\n int Size[100];\n static bool cmp(vector<int> x, vector<int> y) { return x[2] < y[2]; }\n void makeSet(int n) {\n for (int i = 0; i < n; i++) {\n parent[i] = i;\n Size[i] = 1;\n }\n }\n\n int Find(int x) {\n... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class Solution {\npublic:\n int parent[100];\n int Size[100];\n static bool cmp(vector<int> x, vector<int> y) { return x[2] < y[2]; }\n void makeSet(int n) {\n for (int i = 0; i < n; i++) {\n parent[i] = i;\n Size[i] = 1;\n }\n }\n\n int Find(int x) {\n... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class Solution {\npublic:\n int parent[100];\n int Size[100];\n static bool cmp(vector<int> x, vector<int> y) { return x[2] < y[2]; }\n void makeSet(int n) {\n for (int i = 0; i < n; i++) {\n parent[i] = i;\n Size[i] = 1;\n }\n }\n\n int Find(int x) {\n... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class DisjointSet{\n\n public:\n vector<int> parent,size;\n DisjointSet(int n){\n parent.resize(n+1);\n size.resize(n+1);\n for(int i =0;i<=n;i++){\n parent[i] = i;\n size[i] = 1;\n }\n }\n\n int findUPar(int node){\n if(node==parent[n... |
1,613 | <p>Given a weighted undirected connected graph with <code>n</code> vertices numbered from <code>0</code> to <code>n - 1</code>, and an array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between nodes ... | 3 | {
"code": "class DisjointSet{\npublic:\n vector<int>rank,parent,size;\n DisjointSet(int n){\n rank.resize(n,0);\n parent.resize(n);\n size.resize(n,1);\n for(int i=0;i<n;i++){\n parent[i]=i;\n }\n }\n int findUPar(int node){\n if(node==parent[node])retu... |
1,584 | <p>You are given an array of <strong>unique</strong> integers <code>salary</code> where <code>salary[i]</code> is the salary of the <code>i<sup>th</sup></code> employee.</p>
<p>Return <em>the average salary of employees excluding the minimum and maximum salary</em>. Answers within <code>10<sup>-5</sup></code> of the a... | 0 | {
"code": "class Solution {\npublic:\n double average(vector<int>& salary) {\n const auto [min_el, max_el] = minmax_element(salary.begin(), salary.end());\n double avg = 0.0;\n for (int i : salary) {\n if (*min_el == i || *max_el == i) {\n continue;\n }\n ... |
1,584 | <p>You are given an array of <strong>unique</strong> integers <code>salary</code> where <code>salary[i]</code> is the salary of the <code>i<sup>th</sup></code> employee.</p>
<p>Return <em>the average salary of employees excluding the minimum and maximum salary</em>. Answers within <code>10<sup>-5</sup></code> of the a... | 0 | {
"code": "class Solution {\npublic:\n double average(vector<int>& salary) {\n double sum=0;\n double maxsal=salary[0];\n double minsal=salary[0];\n for(int i=0;i<salary.size();i++){\n sum+=salary[i];\n if(salary[i]<minsal)minsal=salary[i];\n if(salary[i... |
1,584 | <p>You are given an array of <strong>unique</strong> integers <code>salary</code> where <code>salary[i]</code> is the salary of the <code>i<sup>th</sup></code> employee.</p>
<p>Return <em>the average salary of employees excluding the minimum and maximum salary</em>. Answers within <code>10<sup>-5</sup></code> of the a... | 0 | {
"code": "class Solution {\npublic:\n double average(vector<int>& salary) {\n sort(salary.begin(), salary.end());\n int sum = 0;\n for(int i = 1; i<salary.size()-1; i++){\n sum+=salary[i];\n }\n\n\n return (double)sum/(salary.size()-2);\n }\n};",
"memory": "8800"... |
1,584 | <p>You are given an array of <strong>unique</strong> integers <code>salary</code> where <code>salary[i]</code> is the salary of the <code>i<sup>th</sup></code> employee.</p>
<p>Return <em>the average salary of employees excluding the minimum and maximum salary</em>. Answers within <code>10<sup>-5</sup></code> of the a... | 0 | {
"code": "class Solution {\npublic:\n double average(vector<int>& salary) \n {\n double x = salary[0], y = salary[0];\n\n for(int i = 1; i < salary.size(); i++)\n {\n if(salary[i] > x)\n {\n x = salary[i];\n }\n\n if(salary[i] < y)... |
1,584 | <p>You are given an array of <strong>unique</strong> integers <code>salary</code> where <code>salary[i]</code> is the salary of the <code>i<sup>th</sup></code> employee.</p>
<p>Return <em>the average salary of employees excluding the minimum and maximum salary</em>. Answers within <code>10<sup>-5</sup></code> of the a... | 0 | {
"code": "class Solution {\npublic:\n double average(vector<int>& salary) {\n int n = salary.size();\n double ans = 0;\n int mini = INT_MAX, maxi = INT_MIN;\n for (int i : salary) {\n mini = min(mini, i);\n maxi = max(maxi, i);\n }\n for (int i : sal... |
1,584 | <p>You are given an array of <strong>unique</strong> integers <code>salary</code> where <code>salary[i]</code> is the salary of the <code>i<sup>th</sup></code> employee.</p>
<p>Return <em>the average salary of employees excluding the minimum and maximum salary</em>. Answers within <code>10<sup>-5</sup></code> of the a... | 0 | {
"code": "class Solution {\npublic:\n double average(vector<int>& salary) \n {\n double x = salary[0], y = salary[0];\n\n for(int i = 1; i < salary.size(); i++)\n {\n if(salary[i] > x)\n {\n x = salary[i];\n }\n\n if(salary[i] < y)... |
1,584 | <p>You are given an array of <strong>unique</strong> integers <code>salary</code> where <code>salary[i]</code> is the salary of the <code>i<sup>th</sup></code> employee.</p>
<p>Return <em>the average salary of employees excluding the minimum and maximum salary</em>. Answers within <code>10<sup>-5</sup></code> of the a... | 1 | {
"code": "class Solution {\npublic:\n double average(vector<int>& salary)\n {\n double sum = 0;\n int maximum = INT_MIN; int minimum = INT_MAX;\n\n for (int &s : salary)\n {\n maximum = max(maximum, s);\n minimum = min(minimum, s);\n sum += s;\n ... |
1,584 | <p>You are given an array of <strong>unique</strong> integers <code>salary</code> where <code>salary[i]</code> is the salary of the <code>i<sup>th</sup></code> employee.</p>
<p>Return <em>the average salary of employees excluding the minimum and maximum salary</em>. Answers within <code>10<sup>-5</sup></code> of the a... | 1 | {
"code": "class Solution {\npublic:\n double average(vector<int>& salary) {\n double ans=0;\n int n=salary.size();\n sort(salary.begin(),salary.end());\n for(int i=1;i<n-1;i++){\n ans+=salary[i];\n }\n return ans/(n-2);\n }\n};",
"memory": "9000"
} |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 0 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int maxLength = 0;\n int l = 0;\n int r = 0;\n int zero = 0;\n\n while(r < nums.size()) {\n if(nums[r] == 0) zero++;\n\n while(zero > 1) {\n if(nums[l] == 0) {\n... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 0 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int i=0,j=0;\n int k=1;\n\n while(j<nums.size()){\n if(nums[j]==0){\n k--;\n }\n if(k<0){\n if(nums[i]==0){\n k++;\n }\n i++;\n ... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 0 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int zerocount=0;\n int i=0,count=0;\n int k=1;\n for(int j=0;j<nums.size();j++){\n if(nums[j]==0){\n zerocount++;\n }\n while(zerocount>k){\n ... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 0 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n // Sliding Window \n int zero=0;\n int i=0,j=0,res=0;\n while(j<nums.size()){\n if(nums[j]==0)\n zero++;\n if(zero>1){\n while(nums[i++]!=0);\n ... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 0 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n\n int max_win = 0;\n int i=0;\n int cur_k = 1;\n int size = nums.size();\n for(int j=0;j<=size;)\n {\n if(j-i > max_win)\n {\n max_win = j-i;\n ... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 0 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int zerocount=0;\n int i=0,count=0;\n int k=1;\n for(int j=0;j<nums.size();j++){\n if(nums[j]==0){\n zerocount++;\n }\n while(zerocount>k){\n ... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 0 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int zerocount=0;\n int i=0,count=0;\n int k=1;\n for(int j=0;j<nums.size();j++){\n if(nums[j]==0){\n zerocount++;\n }\n while(zerocount>k){\n ... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 1 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) \n {\n int k = 1, n = nums.size(),i=0, j;\n \n int ans = INT_MIN;\n \n for( j=0; j<n; j++)\n {\n if(nums[j] == 0)\n {\n k--; \n }\n \n... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 1 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int a =nums.size();\n int i=0;\n int ans=0;\n\n while(i<a){\n int j=i-1;\n int k=i+1;\n int count=0;\n\n if(nums[i]==0){\n while(j>=0 && nums[j]==1){\n ... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int k = 1, ans = 0;\n for(int slow = 0, fast = 0; fast < nums.size(); ++fast)\n {\n if(nums[fast] == 0) --k;\n while(k < 0)\n {\n if(nums[slow] == 0){\n ... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);\n int n = nums.size();\n if(n == 1) return 0;\n\n int ans = INT_MIN;\n int l=0, r=0;\n int zero_cnt = 0; //try to maintain wi... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n vector<pair<int,int>> v;\n int count=1;\n for(int i=1;i<nums.size();i++){\n if(nums[i]==nums[i-1]){\n count++;\n }\n else{\n v.push_back({nums[i-1],c... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(std::vector<int>& nums) {\n std::vector<std::vector<int>> sequences_length{};\n std::vector<int> tmp{};\n int start = -1;\n \n int i = 0;\n bool flag = 0; //is more then one zero between sequnces of 1\n whil... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(std::vector<int>& nums) {\n std::vector<std::vector<int>> sequences_length{};\n std::vector<int> tmp{};\n int start = -1;\n \n int i = 0;\n bool flag = 0; //is more then one zero between sequnces of 1\n whil... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(std::vector<int>& nums) {\n std::vector<std::vector<int>> sequences_length{};\n std::vector<int> tmp{};\n int start = -1;\n \n int i = 0;\n bool flag = 0; //is more then one zero between sequnces of 1\n whil... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int n = nums.size();\n int z[n+1];\n z[0] = 0;\n for(int i = 0; i<nums.size(); i++){\n if(nums[i] == 0) z[i+1] = z[i]+1;\n else z[i+1] = z[i];\n cout<<z[i+1]<<\" \";\n ... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int zer = 0;\n int n= nums.size();\n for(int i=0;i<n;i++){\n if(nums[i]==0) zer += 1;\n }\n if(zer == n) return 0;\n if(zer==0) return n-1;\n if(n == 1 && zer == 1) return 0... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n // Sliding Window \n // int zero=0;\n // int i=0,j=0,res=0;\n // while(j<nums.size()){\n // if(nums[j]==0)\n // zero++;\n // if(zero>1){\n // while(nums[i++]... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\n\npublic:\n\n int longestSubarray(vector<int>& nums) {\n\n // Sliding Window \n\n // int zero=0;\n\n // int i=0,j=0,res=0;\n\n // while(j<nums.size()){\n\n // if(nums[j]==0)\n\n // zero++;\n\n // if(zero>1){\n\n //... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n\n int prefix_frequency_array[nums.size()];\n\n int postfix_frequency_array[nums.size()];\n\n int postfix_frequency = 0;\n\n int prefix_frequency = 0;\n\n for (int i=0,j=nums.size()-1;i<nums.size();i... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "/*\nsliding window: time: O(n), space: O(1)\n - if the current length contains \n 1 0, length guaranteed\n\ninit map to hold window values counts\ninit left and right pointer\nwhile right pointer in bounds-1\n right++\n add elem at nums[right] to window\n if window does not contain exactly ... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int i = 0;\n int j = 0;\n bool check = false;\n int n = nums.size();\n int count = 0;\n int ans = 0;\n unordered_map<int, bool> mp;\n while(i<n && j<n){\n if(nums[j]=... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int length =0;\n int left=0;\n int right = 0;\n unordered_map<int,int> mpp;\n while(right < nums.size()){\n if(nums[right] == 0){\n mpp[nums[right]]++;\n }\n ... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\n const int fastio = [](){ ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();\npublic:\n int longestSubarray(vector<int>& nums) {\n const int nums_len = nums.size();\n\n deque<int> deq;\n int slow = 0;\n int maxl = 0;\n\n for (int fast = ... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int i = 0;\n int j = 0;\n bool check = false;\n int n = nums.size();\n int count = 0;\n int ans = 0;\n unordered_map<int, bool> mp;\n while(i<n && j<n){\n if(nums[j]=... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n stack<int> que; \n int count = 0, answer = 0;\n for(int i = 0; i < nums.size(); i++){\n if(nums[i] == 1){\n count++;\n continue;\n }\n if(que.empty()... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n vector<int> ones;\n\n int limit=0,count=0,maxCount=INT_MIN,k=1;\n for(int i=0;i<nums.size();i++)\n {\n if(limit<k)\n {\n count++;\n ones.push_back(nums[i... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n vector<int> ones;\n\n int limit=0,count=0,maxCount=INT_MIN,k=1;\n for(int i=0;i<nums.size();i++)\n {\n if(limit<k)\n {\n count++;\n ones.push_back(nums[i... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n\n int ans=0;\n int i=0;\n int j=0;\n int zero=0;\n\n vector<int> vec;\n\n int temp=vec.size();\n int k=1;\n\n while(i<nums.size()){\n if(nums[i]==0){\n ... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n long long int leftmax[nums.size()], rightmax[nums.size()];\n // memset(leftmax,0,sizeof(leftmax));\n // memset(rightmax,0,sizeof(rightmax));\n int n= nums.size();\n leftmax[0]= nums[0];\n right... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int n;\n int dp[100001][2];\n int dfs(vector<int>& nums,int curr,int par){\n if(curr>=n){\n if(par==1){\n return -1;\n }\n return 0;\n }\n if(dp[curr][par]!=-1){\n return dp[curr][par];\n ... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n vector <int> v;\n int temp=0,ans=0;\n for(int i=0;i<nums.size();i++){\n if(nums[i]==0){\n if(temp){\n v.push_back(temp);\n }\n temp=0;\n ... |
1,586 | <p>Given a binary array <code>nums</code>, you should delete one element from it.</p>
<p>Return <em>the size of the longest non-empty subarray containing only </em><code>1</code><em>'s in the resulting array</em>. Return <code>0</code> if there is no such subarray.</p>
<p> </p>
<p><strong class="example">Exa... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n std::vector<int> zeroes;\n zeroes.push_back(-1);\n for (int i = 0; i < nums.size(); ++i) {\n if (nums[i] == 0) {\n zeroes.push_back(i);\n }\n }\n zeroes.push_bac... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 0 | {
"code": "#pragma GCC optimize(\"O3\", \"unroll-loops\")\nusing int2=pair<int, int>;\nstruct Myhash {\n size_t operator()(int2 const& s) const {\n size_t h1 = hash<int>{}(s.first);\n size_t h2 = hash<int>{}(s.second);\n return h1 ^ (h2 << 15); \n }\n};\nclass Solution {\npublic:\n bool ... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 0 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n set<pair<int,int>> s;\n s.insert({0,0});\n int x=0,y=0;\n for(auto c:path)\n {\n if(c=='N')\n y++;\n else if(c=='S')\n y--;\n else if(c=='E')\n ... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 0 | {
"code": "#pragma GCC optimize(\"O3\", \"unroll-loops\")\nusing int2=pair<int, int>;\nstruct Myhash {\n size_t operator()(int2 const& s) const {\n size_t h1 = hash<int>{}(s.first);\n size_t h2 = hash<int>{}(s.second);\n return h1 ^ (h2 << 15); \n }\n};\nclass Solution {\npublic:\n bool ... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 0 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n set<pair<int, int>> visited; \n visited.insert({0, 0});\n int x = 0, y = 0; \n \n for (char it : path) {\n if (it == 'N') y++; \n else if (it == 'S') y--; \n else if ... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 0 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n int x = 0, y = 0;\n set<pair<int, int>> visited;\n\n visited.insert({x, y});\n\n for (char dir : path) {\n if (dir == 'N')\n y++;\n else if (dir == 'S')\n y--;... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 0 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n set<pair<int, int>> s;\n\n pair<int, int> org = {0, 0};\n s.insert(org);\n\n for (auto c: path)\n {\n if (c == 'N')\n {\n org.second += 1;\n }\n ... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 1 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n pair<int, int> current = {0,0};\n set<pair<int, int>> visited; \n visited.insert({0,0});\n for(auto p : path) {\n switch(p) \n {\n case 'N':\n current.seco... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 1 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n map<pair<int,int>,int>mp;\n int x=0;\n int y=0;\n mp[{0,0}]=1;\n for(auto it:path){\n if(it=='N') y++;\n else if(it=='E') x++;\n else if(it=='S') y--;\n else if... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 2 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n // Using a map to store visited coordinates and a boolean value\n map<pair<int,int>, bool> visited;\n int x = 0, y = 0; // Initializing the starting point (0,0)\n\n for(auto c : path){\n visited[{x, y... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 2 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n map<pair<int,int> , bool> ExistedCoordinates;\n int x = 0;\n int y = 0;\n for(auto dir : path)\n {\n ExistedCoordinates[{x,y}] = true;\n if(dir == 'N') y++;\n else if(dir ... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 2 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n map<pair<int,int> , bool> ExistedCoordinates;\n int x = 0;\n int y = 0;\n ExistedCoordinates[{x,y}] = true;\n for(auto dir : path)\n {\n if(dir == 'N') y++;\n else if(dir == '... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 2 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n map<pair<int,int> , bool> ExistedCoordinates;\n int x = 0;\n int y = 0;\n ExistedCoordinates[{x,y}] = true;\n for(auto dir : path)\n {\n if(dir == 'N') y++;\n else if(dir == '... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 2 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n map<vector<int>, bool> mp;\n int x = 0, y = 0;\n mp[{0, 0}] = true;\n for(int i = 0; i < path.size(); i++){\n if(path[i] == 'N')y++;\n else if(path[i] == 'S')y--;\n else if(path[... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 2 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n unordered_map<char, pair<int, int>> dir{{'N', {-1,0}}, {'S', {1, 0}}, {'E', {0, 1}}, {'W', {0, -1}}};\n unordered_map<int, unordered_map<int, int>> visited{};\n int x = 0, y = 0;\n for(auto c : path) {\n ... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 2 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n unordered_map<char, pair<int, int>> dir{{'N', {-1,0}}, {'S', {1, 0}}, {'E', {0, 1}}, {'W', {0, -1}}};\n unordered_map<int, unordered_map<int, int>> visited{};\n int x = 0, y = 0;\n visited[x][y] = 1;\n fo... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 2 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n unordered_map<char, pair<int, int>> dir{{'N', {-1,0}}, {'S', {1, 0}}, {'E', {0, 1}}, {'W', {0, -1}}};\n unordered_map<int, unordered_map<int, int>> visited{};\n int x = 0, y = 0;\n for(auto c : path) {\n ... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 2 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n map<int, map<int, bool>> pos;\n int x = 0, y = 0;\n pos[x][y] = true;\n for (char c : path) {\n if (c == 'W')\n x--;\n if (c == 'E')\n x++;\n if (c ... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 2 | {
"code": "class Solution {\npublic:\n \nbool isPathCrossing(string path) {\n\tint arr[2] = { 0 };\n\tunordered_map<int, pair<int, int>> table;\n\ttable[0] = make_pair(0, 0);\n\tfor (int i = 0; i < path.size(); i++)\n\t{\n\t\tif (path[i] == 'N')\n\t\t{\n\t\t\tarr[1]++;\n\t\t}\n\t\telse if (path[i] == 'S')\n\t\t{\n... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 2 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n unordered_set<string> visited;\n int x = 0, y = 0;\n visited.insert(\"0,0\");\n for (char dir : path) {\n if (dir == 'N') y++;\n else if (dir == 'S') y--;\n else if (dir == 'E') ... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 2 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n unordered_set<string> visited;\n\n visited.insert(\"0,0\");\n\n int x = 0;\n int y = 0;\n\n for (char c : path) {\n switch (c) {\n case 'N':\n y++;\n ... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 2 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n unordered_set<string> hs;\n hs.insert(\"0,0\");\n int val1=0,val2=0;\n for(char x:path){\n if(x=='N'){\n val1++;\n }\n else if(x=='S'){\n val1--;\n ... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 3 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n unordered_set<string> st;\n int x=0;\n int y=0;\n\n string key = to_string(x)+\"_\"+to_string(y);\n st.insert(key);\n\n for(char &ch:path)\n {\n if(ch=='E')\n x++;\... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 3 | {
"code": "\nclass Solution {\npublic:\n bool isPathCrossing(string path) {\n // Using a set to track visited positions\n unordered_set<string> visited;\n\n // Starting at the origin (0, 0)\n int x = 0, y = 0;\n // Insert the starting point into the set\n visited.insert(to... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 3 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(const string& path) {\n int x = 0, y = 0; // Starting coordinates\n unordered_map<string, int> coordinate; // Map to track visited positions\n\n // Mark the origin (0,0) as visited\n coordinate[\"0,0\"] = 1;\n\n for (char... |
1,619 | <p>Given a string <code>path</code>, where <code>path[i] = 'N'</code>, <code>'S'</code>, <code>'E'</code> or <code>'W'</code>, each representing moving one unit north, south, east, or west, respectively. You start at the origin <code>(0, 0)</code> on a 2D plane and walk on the path speci... | 3 | {
"code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n unordered_map<char, pair<int, int>> moves;\n moves['N'] = {0, 1};\n moves['S'] = {0, -1};\n moves['W'] = {-1, 0};\n moves['E'] = {1, 0};\n\n unordered_set<string> visited;\n visited.insert(\... |
1,621 | <p>You are given an array of integers <code>nums</code> and an integer <code>target</code>.</p>
<p>Return <em>the number of <strong>non-empty</strong> subsequences of </em><code>nums</code><em> such that the sum of the minimum and maximum element on it is less or equal to </em><code>target</code>. Since the answer may... | 0 | {
"code": "class Solution {\npublic:\n int power(long long base,int expo,int mod)\n {\n long long result=1;\n while(expo>0)\n {\n if(expo % 2)\n {\n result =(result *base)%mod;\n expo=expo-1;\n }\n else\n {\n base =(base * base)%... |
1,621 | <p>You are given an array of integers <code>nums</code> and an integer <code>target</code>.</p>
<p>Return <em>the number of <strong>non-empty</strong> subsequences of </em><code>nums</code><em> such that the sum of the minimum and maximum element on it is less or equal to </em><code>target</code>. Since the answer may... | 0 | {
"code": "class Solution {\npublic:\n int mod=1e9+7;\n int mult(int x,int y){\n return (x*1LL*y)%mod;\n }\n int power(int x,int y){\n int ans=1;\n while(y>0){\n if(y&1){\n ans=mult(ans,x);\n }\n x=mult(x,x);\n y=y>>1;\n ... |
1,621 | <p>You are given an array of integers <code>nums</code> and an integer <code>target</code>.</p>
<p>Return <em>the number of <strong>non-empty</strong> subsequences of </em><code>nums</code><em> such that the sum of the minimum and maximum element on it is less or equal to </em><code>target</code>. Since the answer may... | 0 | {
"code": "class Solution {\npublic:\n int MOD=1000000007;\n int pow(int x, int n){\n if(n==0) return 1;\n if(n==1) return x;\n if(n&1){\n return 1LL*x*pow(1LL*x*x%MOD, n/2)%MOD;\n }\n else{\n return pow(1LL*x*x%MOD, n/2)%MOD;\n }\n }\n int n... |
1,621 | <p>You are given an array of integers <code>nums</code> and an integer <code>target</code>.</p>
<p>Return <em>the number of <strong>non-empty</strong> subsequences of </em><code>nums</code><em> such that the sum of the minimum and maximum element on it is less or equal to </em><code>target</code>. Since the answer may... | 0 | {
"code": "class Solution {\nprivate: \n long long mPow(int x, int y, int mod) {\n if(y == 0) return 1;\n if(y % 2 == 1) return (x * mPow(x, y - 1, mod)) % mod;\n\n long long temp = mPow(x, y / 2, mod);\n return (temp * temp) % mod;\n }\npublic:\n int numSubseq(vector<int>& nums,... |
1,621 | <p>You are given an array of integers <code>nums</code> and an integer <code>target</code>.</p>
<p>Return <em>the number of <strong>non-empty</strong> subsequences of </em><code>nums</code><em> such that the sum of the minimum and maximum element on it is less or equal to </em><code>target</code>. Since the answer may... | 0 | {
"code": "class Solution {\npublic:\n int mod = 1000000007;\n\n long pow(int n, int e) {\n long ans = 1;\n long n1 = (long)n;\n while(e) {\n if(e%2) {\n ans = (ans* n1);\n ans %= mod;\n e -= 1;\n }\n else {\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.