fa
Feedback
LeetCode, GeeksForGeeks Problem of the day solution

LeetCode, GeeksForGeeks Problem of the day solution

رفتن به کانال در Telegram

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

نمایش بیشتر
1 250
مشترکین
+224 ساعت
+147 روز
+2930 روز
آرشیو پست ها
GFG | Problem of the day :

class Solution { public: int minimumOneBitOperations(int n) { vector bits(32,0); for(int i = 31; i >= 0; i--){ if(n & (1 << i)) bits[i] = 1; } int ret = 0; if(bits[31]) ret += (1 << 31); for(int i = 30; i >= 0; i--){ bits[i] ^= bits[i+1]; if(bits[i]) ret += (1 << i); } return ret; } };

LeetCode | Daily challenge :

class Solution{ public: int minimumStep(int n){ int ans = 0; while(n != 1) { n = (n%3) ? n-1 : n/3; ans++; } return ans; } };

GFG | Problem of the day :

class Solution { public: int hammingWeight(uint32_t n) { int cnt=0; while(n>0){ if(n%2==1){ cnt++; } n=n>>1; } return cnt; } };

LeetCode | Daily challenge :

class Solution { public: int isEulerCircuit(int V, vectoradj[]){ int cnt=0; for(int i=0;i

GFG | Problem of the day :

class Solution { public: int numberOfWays(string corridor) { int ans=1,module=1000000007; vector seatIndex; for(int index=0;index

LeetCode | Daily challenge :

class Solution { public: int sumOfDependencies(vector adj[], int V) { int res = 0; for(int i = 0; i < V; i++) res += adj[i].size(); return res; } };

GFG | Problem of the day :

class Solution { public: int mod = 1e9+7; vector> dp; int call(int n , map>& m , int pos){ if(n==0)return 1; if(dp[pos][n] != -1)return dp[pos][n]; int ans = 0; for(int j =0;j> m; m[1] = {6,8}; m[2] = {7,9}; m[3] = {4,8}; m[4] = {3,9,0}; m[5] = {}; m[6] = {1,7,0}; m[7] = {2,6}; m[8] = {1,3}; m[9] = {2,4}; m[0] = {4,6}; dp = vector>(11 , vector(n+1,-1)); int ans = 0; for(int i=0;i<=9;i++){ ans = (ans%mod + call(n-1,m,i)%mod)%mod; } return ans; } };

LeetCode | Daily challenge :

class Solution { public: //Function to detect cycle using DSU in an undirected graph. vector parent; vector rank; int find(int x) { if(parent[x] == x) { return x; } parent[x] = find(parent[x]); return parent[x]; } void union1(int x, int y) { int x_rep = find(x); int y_rep = find(y); if(x_rep == y_rep) { return; } if(rank[x_rep] < rank[y_rep]) { parent[x_rep] = y_rep; } else if(rank[x_rep] > rank[y_rep]) { parent[y_rep] = x_rep; } else { parent[y_rep] = x_rep; rank[x_rep]++; } } int detectCycle(int V, vectoradj[]) { parent.resize(V); rank.resize(V); for(int i = 0; i < V; i++) { parent[i] = i; rank[i] = 0; } set> s; for(int v = 0; v < V; v++) { for(auto u : adj[v]) { if(s.find({u, v}) != s.end() or s.find({v, u}) != s.end()) { continue; } s.insert({u, v}); int u_rep = find(u); int v_rep = find(v); if(u_rep == v_rep) { return true; } union1(u, v); } } return false; } };

GFG | Problem of the day :

class Solution { public: int largestSubmatrix(vector>& matrix) { int m = matrix.size(), n = matrix[0].size(); int ans = 0; for(int j = 0; j < n; j++) for(int i = 1; i < m; i++) if(matrix[i][j] == 1) matrix[i][j] += matrix[i-1][j]; for(int i = 0; i < m; i++) { sort(matrix[i].begin(), matrix[i].end()); reverse(matrix[i].begin(), matrix[i].end()); for(int j = 0; j < n; j++) ans = max(ans, matrix[i][j]*(j+1)); } return ans; } };

LeetCode | Daily challenge :

class Solution{ public: vector ans; vector pattern(int N){ if(N<=0){ ans.push_back(N); return ans; } ans.push_back(N); pattern(N-5); ans.push_back(N); return ans; } };