es
Feedback
LeetCode, GeeksForGeeks Problem of the day solution

LeetCode, GeeksForGeeks Problem of the day solution

Ir al canal en Telegram

Complete daily challenges from LeetCode, GeeksForGeeks and redeem their rewards Channel link : https://t.me/leetcode_gfg_potd

Mostrar más
1 250
Suscriptores
+224 horas
+147 días
+2930 días
Archivo de publicaciones
GFG | Problem of the day :

class Solution { public: int constrainedSubsetSum(vector& nums, int k) { deque dq; int s=INT_MIN; for(int i=0;i0) dq.push_back(nums[i]); if(i>=k && dq.front()==nums[i-k] && !dq.empty()) dq.pop_front(); } return s; } };

LeetCode | Daily challenge :

class Solution { public: long long sumOfDivisors(int N) { long long ans=0; for(int i=1;i<=N;i++){ ans += i*(N/i); } return ans; } };

GFG | Problem of the day :

class NestedIterator { public: vector v; int index; void Recursion(vector& nums) { int i=0; while(i &nestedList) { index=0; Recursion(nestedList); } int next() { if(hasNext()){ return v[index++]; } return -1; } bool hasNext() { if(index

LeetCode | Daily challenge :

class Solution { public: int isPossible(int N, int arr[]) { long long sum = 0; for(int i=0;i

GFG | Problem of the day :

class Solution { public: bool backspaceCompare(string s, string t) { stack st1, st2; for(int i=0;i0){ st1.pop(); } else if(s[i]!='#'){ st1.push(s[i]); } } for(int i=0;i0){ st2.pop(); } else if(t[i]!='#'){ st2.push(t[i]); } } return st1==st2; } };

LeetCode | Daily challenge :

class Solution { public: //Function to find the level of node X. int nodeLevel(int V, vector adj[], int X) { queue q; vector vis(V, 0); int level = 0; q.push(0); vis[0] = 1; while (!q.empty()) { int size = q.size(); for (int i = 0; i < size; i++) { int adjnode = q.front(); q.pop(); if (adjnode == X) { return level; } for (auto x : adj[adjnode]) { if (!vis[x]) { vis[x] = 1; q.push(x); } } } level++; } return -1; } };

GFG | Problem of the day :

class Solution { public: int minimumTime(int n, vector>& relations, vector& time) { vectoradj[n]; vectorindegree(n,0); for(auto relation:relations){ int u = relation[0]-1; int v = relation[1]-1; adj[u].push_back(v); indegree[v]++; } queueq; vectormaxTime(n,0); for(int i=0;i

LeetCode | Daily challenge :

class Solution { public: vector eventualSafeNodes(int V, vector adj[]) { int indegree[V]={0}; vector adjR[V]; for(int i=0;i q; for(int i=0;i ans; while(!q.empty()){ int node = q.front(); q.pop(); ans.push_back(node); for(auto it:adjR[node]){ indegree[it]--; if(indegree[it]==0){ q.push(it); } } } sort(ans.begin(), ans.end()); return ans; } };

GFG | Problem of the day :

class Solution { public: int findRoot(int n, vector<int>& left, vector<int>& right) { unordered_set<int> children; for(int i = 0; i < left.size(); i++) { children.insert(left[i]); } for(int i = 0; i < right.size(); i++) { children.insert(right[i]); } for(int i = 0; i < n; i++) { if(children.find(i) == children.end()) { return i; } } return -1; } bool validateBinaryTreeNodes(int n, vector<int>& leftChild, vector<int>& rightChild) { int root = findRoot(n, leftChild, rightChild); if(root == -1) { return false; } unordered_set<int> seen; stack<int> st; seen.insert(root); st.push(root); while(!st.empty()) { int node = st.top(); st.pop(); int children[] = {leftChild[node], rightChild[node]}; for(int i : children) { if(i != -1) { if(seen.find(i) != seen.end()) { return false; } st.push(i); seen.insert(i); } } } return seen.size() == n; } };

LeetCode | Daily challenge :

class Solution{ public: vector> transitiveClosure(int N, vector> graph) { for(int via = 0; via < N; via++) for(int src = 0; src < N; src++) for(int dest = 0; dest < N; dest++) if(graph[src][via] && graph[via][dest] || src == dest) graph[src][dest] = 1; return graph; } };