id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class Solution {\npublic:\n vector<int>parent,rank,size;\n void dsu(int n){\n rank.resize(n+1,0);\n parent.resize(n+1);\n size.resize(n+1,1);\n for(int i=0;i<=n;i++){\n parent[i]=i;\n }\n }\n int findpar(int node){\n if(node==parent[node])ret... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class Solution {\npublic:\n unordered_map<int, vector<int>> prime2index;\n unordered_map<int, vector<int>> index2prime;\n void dfs(int index, vector<int>& visitedIndex, unordered_map<int,bool>& visitedPrime){\n if(visitedIndex[index] == true) return;\n visitedIndex[index] = true;\n\n... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class Solution {\npublic:\n unordered_map<int, vector<int>> prime2index;\n unordered_map<int, vector<int>> index2prime;\n void dfs(int index, vector<int>& visitedIndex, unordered_map<int,bool>& visitedPrime){\n if(visitedIndex[index] == true) return;\n visitedIndex[index] = true;\n\n... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class Solution {\npublic:\n unordered_map<int, vector<int>> prime2index;\n unordered_map<int, vector<int>> index2prime;\n void dfs(int index, vector<int>& visitedIndex, unordered_map<int,bool>& visitedPrime){\n if(visitedIndex[index] == true) return;\n visitedIndex[index] = true;\n\n... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class Solution {\npublic:\n vector<int> adj[100005];\n int vis[100005];\n void dfs(int u , int p){\n vis[u] = 1;\n for(int v : adj[u]){\n if(v == p)continue;\n if(vis[v] == 0)dfs(v , u);\n }\n }\n\n // linear sieve\n int lpf[100005]; // lpf[x] : ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class Solution {\npublic:\n vector<int> adj[100005];\n int vis[100005];\n void dfs(int u , int p){\n vis[u] = 1;\n for(int v : adj[u]){\n if(v == p)continue;\n if(vis[v] == 0)dfs(v , u);\n }\n }\n\n // linear sieve\n int lpf[100005]; // lpf[x] : ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "vector<bool> vis;\nvector<vector<int>> g;\n\nvoid dfs(int u, int from,vector<vector<int>>& g) {\n vis[u] = 1;\n for (auto& v : g[u]) {\n if (!vis[v] && v != from)\n dfs(v, u, g);\n }\n}\n\nclass Solution {\npublic:\n bool canTraverseAllPairs(vector<int>& a) {\n int n = ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class Solution {\npublic:\n using bitset = std::vector<std::int8_t>;\n\n std::vector<int> generatePossibleDivizors(int n) {\n n /= 2;\n auto visit = bitset(n);\n \n for (auto j = 4; j < n; j += 2) {\n visit[j] = true;\n }\n for (auto i = 3; i < n /... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class Solution {\npublic:\n using bitset = std::vector<std::int8_t>;\n\n std::vector<int> generatePossibleDivizors(int n) {\n n /= 2;\n auto visit = bitset(n);\n \n for (auto j = 4; j < n; j += 2) {\n visit[j] = true;\n }\n for (auto i = 3; i < n /... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class Solution {\npublic:\n using bitset = std::vector<std::int8_t>;\n\n std::vector<int> generatePossibleDivizors(int n) {\n n /= 2;\n auto visit = bitset(n);\n \n for (auto j = 4; j < n; j += 2) {\n visit[j] = true;\n }\n for (auto i = 3; i < n /... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class Solution {\npublic:\n map<int,vector<int>> index2prime;\n map<int,vector<int>> prime2index;\n map<int,int> visitIndex;\n map<int,int> visitPrime;\n\n void f(int id){\n \n vector<int> v = index2prime[id];\n visitIndex[id]=1;\n for(int id = 0;id<v.size();id++)... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "#define ll long long\n\nclass DSU{\npublic:\n vector<ll> parents;\n vector<ll> rank;\n DSU(ll n){\n parents.resize(n, 0);\n rank.resize(n, 0);\n for(int i=1; i<n; i++){\n parents[i] = i;\n }\n }\n ll findparent(ll a){\n if(a==parents[a]) return a... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class Solution {\npublic:\n vector<int> adj[100005];\n int vis[100005];\n void dfs(int u , int p){\n vis[u] = 1;\n for(int v : adj[u]){\n if(v == p)continue;\n if(vis[v] == 0)dfs(v , u);\n }\n }\n\n // linear sieve\n int lpf[100005]; // lpf[x] : ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class Solution {\n \n int par[100007];int size[100007];\n void dsu(int n){\n for(int i=1; i<=n; i++) par[i]=i,size[i]=1;\n }\n\n int find(int x){\n if( x==par[x]) return x;\n return par[x]=find(par[x]);\n }\n\n void unite(int x, int y){\n int a=find(x),b=fin... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class ds {\n public:\n vector<int> parent;\n vector<int> rank;\n ds(int n) {\n parent.resize(n, 0);\n rank.resize(n, 0);\n\n for (int i = 0; i < n; i++) \n parent[i] = i;\n }\n\n int find(int node) {\n return p... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class ds {\n public:\n vector<int> parent;\n vector<int> rank;\n ds(int n) {\n parent.resize(n, 0);\n rank.resize(n, 0);\n\n for (int i = 0; i < n; i++) \n parent[i] = i;\n }\n\n int find(int node) {\n return p... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class DisjointSet {\n public:\n vector<int> parent;\n vector<int> rank;\n DisjointSet(int n) {\n parent.resize(n, 0);\n rank.resize(n, 0);\n\n for (int i = 0; i < n; i++) \n parent[i] = i;\n }\n\n int find(int node) {\n ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "#include <vector>\nusing namespace std;\n\nclass DisjointSet {\npublic:\n vector<int> rank, parent, size;\n\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 ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "#include <vector>\nusing namespace std;\n\nclass DisjointSet {\npublic:\n vector<int> rank, parent, size;\n\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 ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class UnionFind {\nprivate:\n int n, *parent, *rank;\npublic:\n int set_size;\n UnionFind(){}\n UnionFind(int a) { //a: set size, {1,2...n}\n n=set_size=a;\n parent=new int[n+1];\n rank=new int[n+1];\n for (int i=0;i<n;i++) parent[i]=i, rank[i]=1;\n }\n\n int f... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class Solution {\npublic: \n // const int MAXN = 100001;\n vector<vector<int>> prime_factors;\n\n void prime (int MAXN){\n prime_factors.resize(MAXN + 1);\n \n for (int i = 2; i <= MAXN; i++) {\n if (prime_factors[i].empty()) \n { \n for (in... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 2 | {
"code": "class Solution {\npublic:\n int findparent(int u,vector<int>&par)\n {\n if(u==par[u])\n return u;\n return par[u]=findparent(par[u],par);\n }\n void Union(int u,int v,vector<int>&par)\n {\n int pu=findparent(u,par);\n int pv=findparent(v,par);\n ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class DisjointSet {\n vector<int> rank, parent;\npublic:\n DisjointSet(int n) {\n rank.resize(n + 1, 0);\n parent.resize(n + 1);\n for (int i = 0; i <= n; i++) {\n parent[i] = i;\n }\n }\n\n int findUPar(int node) {\n if (node == parent[node])\n ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class DSU {\n vector<int> e;\npublic:\n DSU(int n) { e = vector<int> (n, -1); }\n int leader(int x) { return e[x] < 0 ? x : e[x] = leader(e[x]); }\n void merge(int x, int y) {\n x = leader(x);\n y = leader(y);\n if(x == y) return;\n if(e[x] > e[y]) swap(x, y);\n ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class DSU {\n vector<int> e;\npublic:\n DSU(int n) { e = vector<int> (n, -1); }\n int leader(int x) { return e[x] < 0 ? x : e[x] = leader(e[x]); }\n void merge(int x, int y) {\n x = leader(x);\n y = leader(y);\n if(x == y) return;\n if(e[x] > e[y]) swap(x, y);\n ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class DSU {\n vector<int> e;\npublic:\n DSU(int n) { e = vector<int> (n, -1); }\n int leader(int x) { return e[x] < 0 ? x : e[x] = leader(e[x]); }\n void merge(int x, int y) {\n x = leader(x);\n y = leader(y);\n if(x == y) return;\n if(e[x] > e[y]) swap(x, y);\n ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class DSU {\n vector<int> e;\npublic:\n DSU(int n) { e = vector<int> (n, -1); }\n int leader(int x) { return e[x] < 0 ? x : e[x] = leader(e[x]); }\n void merge(int x, int y) {\n x = leader(x);\n y = leader(y);\n if(x == y) return;\n if(e[x] > e[y]) swap(x, y);\n ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class Solution {\npublic:\n class DSU {\n vector<int> parent;\n vector<int> size;\n\n public:\n DSU(int n) {\n for (int i = 0; i < n; i++) {\n parent.push_back(i);\n size.push_back(1);\n }\n }\n int find(int n) {\n... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class DSU {\n vector<int> parent;\n vector<int> size;\n\npublic:\n DSU(int N) {\n for (int i = 0; i <= N; i++) {\n parent.push_back(i);\n size.push_back(1);\n }\n }\n\n int find(int x) { return parent[x] == x ? x : parent[x] = find(parent[x]); }\n\n voi... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class DSU {\n vector<int> parent;\n vector<int> size;\n\npublic:\n DSU(int N) {\n for (int i = 0; i <= N; i++) {\n parent.push_back(i);\n size.push_back(1);\n }\n }\n\n int find(int x) { return parent[x] == x ? x : parent[x] = find(parent[x]); }\n\n voi... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class DSU {\n vector<int> parent;\n vector<int> size;\n\npublic:\n DSU(int N) {\n for (int i = 0; i <= N; i++) {\n parent.push_back(i);\n size.push_back(1);\n }\n }\n\n int find(int x) { return parent[x] == x ? x : parent[x] = find(parent[x]); }\n\n voi... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class DSU {\n\n vector<int> parent;\n\n vector<int> size;\n\npublic:\n\n DSU(int N) {\n\n for (int i = 0; i <= N; i++) {\n\n parent.push_back(i);\n\n size.push_back(1);\n\n }\n\n }\n\n int find(int x) { return parent[x] == x ? x : parent[x] = find(parent[x... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class DSU {\n vector<int> parent;\n vector<int> size;\n\npublic:\n DSU(int N) {\n for (int i = 0; i <= N; i++) {\n parent.push_back(i);\n size.push_back(1);\n }\n }\n\n int find(int x) { return parent[x] == x ? x : parent[x] = find(parent[x]); }\n\n voi... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class DSU {\n\n vector<int> parent;\n\n vector<int> size;\n\npublic:\n\n DSU(int N) {\n\n for (int i = 0; i <= N; i++) {\n\n parent.push_back(i);\n\n size.push_back(1);\n\n }\n\n }\n\n int find(int x) { return parent[x] == x ? x : parent[x] = find(parent[x... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class DSU{\n vector<int> par, rank;\n public:\n DSU(int N){\n for(int i = 0; i <= N; i++){\n par.push_back(i);\n rank.push_back(1);\n }\n }\n int find(int i){\n return i == par[i] ? par[i] : find(par[i]);\n }\n void connect(int a, int b){\n ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class DSU{\n vector<int> parent;\n vector<int> rank;\npublic:\n DSU(int n){\n parent.resize(n + 1);\n rank.resize(n + 1);\n for(int i = 0; i <= n; ++i){\n parent[i] = i;\n }\n }\n\n int findPar(int node){\n if(node == parent[node]) return node;\n... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class Solution {\n class disjointSet{\n public:\n vector<int>parent,size;\n disjointSet(int n){\n parent.resize(n);\n size.resize(n);\n for(int i=0;i<n;i++){\n parent[i]=i;\n }\n }\n int findUPar(int node){\n ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class Solution {\npublic:\n struct dsu\n {\n vector<int> sz;\n vector<int> p;\n void initialize(int n)\n {\n sz.resize(n,1);\n p.resize(n,0);\n for(int i=0; i<n; i++) p[i]=i;\n }\n int get(int u)\n {\n if(p[u... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class Solution {\npublic:\n struct dsu\n {\n vector<int> sz;\n vector<int> p;\n void initialize(int n)\n {\n sz.resize(n,1);\n p.resize(n,0);\n for(int i=0; i<n; i++) p[i]=i;\n }\n int get(int u)\n {\n if(p[u... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class Solution {\n\nprivate:\n vector<int> parent, size;\n int Find(int node){\n if (parent[node] == node) return node;\n return parent[node] = Find(parent[node]);\n }\n\n void Union(int node1, int node2){\n int root1 = Find(node1);\n int root2 = Find(node2);\n ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class Solution {\n\nprivate:\n vector<int> parent, size;\n int Find(int node){\n if (parent[node] == node) return node;\n return parent[node] = Find(parent[node]);\n }\n\n void Union(int node1, int node2){\n int root1 = Find(node1);\n int root2 = Find(node2);\n ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class Solution {\npublic:\n vector<int>par;vector<int>sz;\n void make(int x){\n par[x]=x;sz[x]=1;\n }\n int find(int x){\n if(par[x]==x)return x;\n return par[x]=find(par[x]);\n }\n void Union(int x,int y){\n x=find(x);y=find(y);\n if(x==y)return ;\n ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class Solution {\n vector<int> factors(int num){\n vector<int> ans;\n int n = num;\n for(int i=2;i*i<=n;i++)\n {\n while(n%i==0){\n ans.push_back(i);\n n/=i;\n }\n }\n if(n>1) ans.push_back(n);\n return ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class Solution {\npublic:\n vector<int>P;\n int sets;\n bool canTraverseAllPairs(vector<int>& nums) {\n int n=nums.size();\n if(P.size()==0)build_Prime();\n build_set(n);\n vector<vector<int>>groups(100005);\n for(int i=0;i<nums.size();i++)if(nums[i]!=1){\n ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class Solution {\npublic:\n vector<int>P;\n int sets;\n bool canTraverseAllPairs(vector<int>& nums) {\n int n=nums.size();\n if(P.size()==0)build_Prime();\n build_set(n);\n vector<vector<int>>groups(100005);\n for(int i=0;i<nums.size();i++)if(nums[i]!=1){\n ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class Solution {\npublic:\n int find( int x , vector<int>& parent )\n {\n if( parent[x] == x ) return x;\n return parent[x] = find( parent[x] , parent );\n }\n\n void unionbyrank( int a, int b, vector<int>& parent)\n {\n int x = find( a , parent );\n int y... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class Solution {\npublic:\n bool canTraverseAllPairs(vector<int>& nums) {\n map<int, set<int> > primeUnion;\n vector<int> parent(100001, -1);\n int numParents = 0;\n\n for (int num : nums){\n if (num == 1 && nums.size() > 1)\n return false;\n ... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class Solution {\npublic:\n int N=100005;\n vector<int> sieve;\n set<int> pF(int x){\n set<int> factors;\n while(x>1){\n int t=sieve[x];\n while(x%t==0)x/=t;\n factors.insert(t);\n }\n return factors;\n }\n bool canTraverseAllPairs... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "\nstruct dsu {\n vector<int> par, rk;\n int connected;\n\n void init(int n) {\n par.resize(n);\n rk.resize(n, 1);\n iota(par.begin(),par.end(), 0);\n connected = n;\n }\n\n int getp(int x) {\n if (par[x] == x) return x;\n return par[x] = getp(par[x])... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class Solution {\npublic:\n\nvector<int> seive(int n){\n vector<int> p(n+1,1),lp(n+1,-1);\n p[0]=0;p[1]=0;\n for(int i=2;i*i<=n;i++){\n if(!p[i]) continue;\n lp[i]=i;\n for(int j=i*i;j<=n;j+=i){\n p[j]=0;\n if(lp[j]==-1) lp[j]=i;\n }\n }\n re... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "\nclass 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] =... |
2,827 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and you are allowed to <strong>traverse</strong> between its indices. You can traverse between index <code>i</code> and index <code>j</code>, <code>i != j</code>, if and only if <code>gcd(nums[i], nums[j]) > 1</code>, where <code>gcd</cod... | 3 | {
"code": "class union_find {\npublic:\n vector<int> p;\n vector<int> r;\n union_find(int n) {\n p.resize(n, 0);\n r.resize(n, 0);\n \n for(int i = 0 ; i < n ; i++) {\n p[i] = i;\n }\n }\n \n int Find(int x) {\n if(p[x] != x) {\n p[x] =... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 0 | {
"code": "#include <ranges>\nclass Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n for(auto [index, val] : std::views::enumerate(capacity)) {\n val -= rocks[index];\n }\n std::ranges::sort(capacity);\n int result{};\n for(in... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 0 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n ios::sync_with_stdio(0);\n int n=capacity.size();\n for(int i=0;i<n;i++)\n capacity[i]-=rocks[i];\n sort(capacity.begin(),capacity.end());\n int j... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 0 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& n, vector<int>& rocks, int additionalRocks) {\n int ans=0;\n for(int i=0;i<n.size();i++){\n n[i]-=rocks[i];\n }\n sort(n.begin(),n.end());\n for(int i=0;i<n.size();i++){\n ans+=n[i];\n if... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 0 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n int count = 0;\n // sort(rocks.begin() , rocks.end());\n for(int i =0; i<rocks.size(); i++)\n capacity[i] -= rocks[i];\n \n sort(capacity.begin() , capacity.end());\n \n ... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 0 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n int n = capacity.size();\n \n int count = 0;\n for(int i=0; i<n; i++){\n capacity[i]= capacity[i]-rocks[i];\n if(capacity[i] == 0){\n ... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 0 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n int n = capacity.size();\n for(int i=0; i<n; i++){\n rocks[i] = capacity[i] - rocks[i];\n }\n\n sort(begin(rocks), end(rocks));\n int count = 0;\n... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 0 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n int n=capacity.size(),count=0;\n int arr[n];\n for(int i=0;i<n;i++){\n arr[i]=capacity[i]-rocks[i];\n }\n sort(arr,arr+n);\n for(i... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 0 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n int n = size(rocks);\n vector<int> v(n);\n for ( int i=0; i<n; i++ ) v[i] = capacity[i] - rocks[i];\n \n ranges::sort(v);\n int ret = 0;\n for ... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 0 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n vector<int> queue(rocks.size());\n for (size_t i = 0; i < rocks.size(); ++i) queue[i] = capacity[i] - rocks[i];\n ranges::sort(queue);\n\n int res = 0;\n for... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 0 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n vector<int> freeSpaces(rocks.size());\n for (int i{}; i < rocks.size(); i++) {\n freeSpaces[i] = capacity[i] - rocks[i];\n }\n ranges::sort(freeSpaces);\... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 0 | {
"code": "class Solution {\npublic:\n using MinHeap = priority_queue<int, vector<int>, greater<int>>;\n\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n vector<int> queue(rocks.size());\n //MinHeap queue;\n for (size_t i = 0; i < rocks.size(); ++i)\n ... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 0 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& c, vector<int>& r, int a) {\n // I have to find out differance between Current rocks and max capacity of those rocks \n //store in one vector and sort the vector\n // Just substruct differance from additionalrocks\n\n int n = ... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 0 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n int n=capacity.size();\n int bag=0;\n\n vector<int>required(n,0);\n\n for(int i=0;i<n;i++){\n int capacity_rock=capacity[i];\n int rock_have=r... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 0 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n vector<int> diffs;\n diffs.reserve(rocks.size());\n for (int i = 0; i < rocks.size(); i++) {\n diffs.push_back(capacity[i] - rocks[i]);\n }\n sort... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 0 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n int n = capacity.size();\n int count = 0;\n vector<int> vec(n);\n \n for(int i = 0; i<n; i++) {\n vec[i] = capacity[i] - rocks[i];\n }\n ... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 1 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) { int count = 0;\n vector<int> rem(capacity.size());\n\n for (int i = 0; i < capacity.size(); i++) {\n rem[i] = capacity[i] - rocks[i];\n }\n\n \n s... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 1 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& c, vector<int>& r, int aR) {\n int n = c.size(); \n vector<int> rc(n);\n for( int i=0 ; i<n ; i++ ){\n rc[i] = c[i]-r[i];\n } \n sort( rc.begin(), rc.end() );\n\n for( int i=0 ; i<n ; i++ ){\n ... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 1 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n int n = capacity.size();\n vector<int> req(n,0);\n int count = 0;\n for(int i=0; i<n; i++){\n req[i]= capacity[i]-rocks[i];\n \n }\n ... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 1 | {
"code": "class Solution {\npublic:\n\n static bool compare(pair<int, int> p1, pair<int, int> p2) {\n return (p1.first - p1.second) < (p2.first - p2.second);\n }\n\n int maximumBags(vector<int>& capacity, vector<int>& rocks,\n int additionalRocks) {\n int n = rocks.size();\n... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 1 | {
"code": "class Solution {\npublic:\n\n static bool compare(pair<int, int> p1, pair<int, int> p2) {\n return (p1.first - p1.second) < (p2.first - p2.second);\n }\n\n int maximumBags(vector<int>& capacity, vector<int>& rocks,\n int additionalRocks) {\n int n = rocks.size();\n... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 1 | {
"code": "class Solution\n{\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int add)\n {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL), cout.tie(NULL);\n\n std::vector<std::pair<int, int>> pairs(rocks.size());\n for (int i = 0; i < rocks.size(); i++)\n ... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 1 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& cap, vector<int>& r, int tot) {\n int n= cap.size();\n vector<pair<int,int>> d(n);\n\n for(int i=0;i<n;i++){\n d[i]= {cap[i]-r[i],i};\n }\n\n sort(begin(d),end(d));\n\n int c=0;\n for(int i=0... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 1 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n int n = rocks.size();\n vector <pair <int,int>> nums(n);\n for(int i = 0;i<n;i++) {\n pair <int,int> temp = {capacity[i] , rocks[i]};\n nums[i] = tem... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 1 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>&c, vector<int>& r, int val) {\n ios::sync_with_stdio(0);\n vector<int>ans;\n int n=c.size();\n for(int i=0;i<n;i++) ans.push_back(c[i]-r[i]);\n sort(ans.begin(),ans.end());\n int len=0,ct=0... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 1 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n priority_queue<int, vector<int>, greater<>>pq;\n int out{};\n\n for (int i{}; const auto r : rocks){\n if (!(capacity[i]-r)){\n ++out;\n ... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 1 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) \n {\n vector<int> diff;\n for(int i=0; i < rocks.size(); i++)\n {\n diff.push_back(capacity[i] - rocks[i]);\n }\n int count = 0;\n sort(dif... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n priority_queue<int,vector<int>,greater<int>>pq;\n int n = capacity.size();\n int count = 0;\n vector<int>diff(n);\n for(int i=0;i<n;i++){\n diff[i... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n vector<int>dif(capacity.size());\n priority_queue<int,vector<int>,greater<int>>pq;\n for(int i=0;i<capacity.size();i++){\n dif[i]=capacity[i]-rocks[i];\n ... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n int n = capacity.size();\n vector<int> reqdmaxm(n);\n for (int i = 0; i < n; i++) {\n reqdmaxm[i] = capacity[i] - rocks[i];\n }\n int count = 0;\n... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n static bool cmp(pair<int,int> a,pair<int,int> b){\n return a.first-a.second < b.first-b.second;\n }\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n int n=capacity.size();\n vector<pair<int,int>> a;\n for(... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n int n = rocks.size();long long capacitySum = 0;int cnt = 0;\n for(int a:capacity) capacitySum+=a;\n if(capacitySum < additionalRocks) return n;\n vector<pair<int,in... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int> cp, vector<int> rocks, int ar) {\n int n=cp.size();\n int cnt=0;\n vector<int >vc;\n for(int i=0;i<n;i++){\n if(cp[i]<=rocks[i]){\n cnt++;\n }\n else{\n vc.p... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int> capacity, vector<int> rocks, int ar) {\n int n=capacity.size();\n int cnt=0;\n vector<int >vc;\n for(int i=0;i<n;i++){\n if(capacity[i]<=rocks[i]){\n cnt++;\n }\n else{\n ... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n static bool comp(pair<int,int>& a,pair<int,int>& b){\n return a.first-a.second<b.first-b.second;\n }\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n ios::sync_with_stdio(false);\n cin.tie(NULL);\n cout.ti... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n vector<pair<int,int>> cr;\n int n=rocks.size();\n int count=0;\n for(int i=0;i<n;i++){\n cr.push_back({capacity[i],rocks[i]});\n }\n sort(c... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n \n int n=rocks.size();\n vector<pair<int,int>>v;\n\n for(int i=0;i<n;i++){\n int cap=capacity[i];\n int contain=rocks[i];\n\n v.pus... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n vector<pair<int,int>> cr;\n int n=rocks.size();\n int count=0;\n for(int i=0;i<n;i++){\n cr.push_back({capacity[i],rocks[i]});\n }\n sort(c... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n int cnt = 0;\n\n vector<long long> diff;\n\n for(int i = 0; i < rocks.size(); ++i) {\n diff.push_back(capacity[i]-rocks[i]);\n }\n\n sort(diff.be... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n std::map<int, int> m = {}; // bigger to smaller or reverse?\n\n const int N = capacity.size();\n for (int i = 0; i < N; i++) {\n m[capacity[i] - rocks[i]]+... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n int n=rocks.size();\n map<int,int>m;\n for(int i=0;i<n;i++){\n int diff=capacity[i]-rocks[i];\n m[diff]++;\n }\n int ans=0;\n fo... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n map<int,int> omap;\n int total = 0;\n for(int i = 0; i<capacity.size(); i++)\n {\n int diff = capacity[i]-rocks[i];\n if(diff == 0)\n ... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n map<int, int> mpp;\n for(int i = 0; i < rocks.size(); i++){\n mpp[capacity[i] - rocks[i]]++;\n }\n int ans = 0;\n for(auto &pair : mpp){\n ... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n vector<pair<int,pair<int,int>>> v;\n for(int i=0;i<capacity.size();i++)\n {\n int requirement=capacity[i]-rocks[i];\n v.push_back({requirement,{capac... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "#define pii pair<int, pair<int,int>>\nclass Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n // {space available, {capacity, rocks}}\n priority_queue<pii, vector<pii>, greater<pii>>pq; \n\n for(int bag = 0; bag < capacity.size... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n static bool cmp(pair<pair<int,int>,int> &a, pair<pair<int,int>,int> &b){\n return a.second < b.second;\n }\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n // {{capacity[i],rocks[i]},capacity[i]-rocks[i]};\n vecto... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n int n = capacity.size();\n vector<int> tem;\n vector<long long> pre ;\n for(int i=0;i<n;i++){\n tem.push_back(capacity[i]-rocks[i]);\n }\n ... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n typedef pair<long long,long long> p;\n\n int maximumBags(vector<int>& capacity, vector<int>& rocks, int extra) {\n vector<p> v;\n for(long long i =0; i<capacity.size(); i++){\n v.push_back({capacity[i], rocks[i]});\n }\n\n auto comp =... |
2,366 | <p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</co... | 3 | {
"code": "class Solution {\npublic:\n static bool comp(vector<int>&a,vector<int>&b){\n return (a[0]-a[1])<(b[0]-b[1]);\n}\nint maximumBags(vector<int>& capacity, vector<int>& rocks, int additionalRocks) {\n int n=capacity.size();\n int ans=0;\n vector<vector<int>>arr(n,vector<int>(2));\n for(int i=... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.