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: string destCity(vector>& paths) { unordered_mapa; for(int i=0;i

LeetCode | Daily challenge :

class Solution{ public: int dp[100005]; const int M = 1e9+7; int nthPoint(int n){ if(dp[0]==0){ for(int i=0;i<100005;i++){ dp[i]=-1; } } if(n==0 || n==1) return 1; if(dp[n]!=-1) return dp[n]; return dp[n]=(nthPoint(n-1)%M+nthPoint(n-2)%M)%M; } };

GFG | Problem of the day :

class Solution { public: vector> onesMinusZeros(vector>& grid) { vector row(grid.size()); vector col(grid[0].size()); for(int i = 0; i < grid.size(); ++i){ for(int j = 0; j < grid[0].size(); ++j){ row[i] += grid[i][j]; col[j] += grid[i][j]; } } for(int i = 0; i < grid.size(); ++i){ for(int j = 0; j < grid[0].size(); ++j){ grid[i][j] = row[i] + col[j] - (grid.size()-row[i]) - (grid[0].size()-col[j]); } } return grid; } };

LeetCode | Daily challenge :

class Solution{ public: long long M=1e9+7; long long countWays(int n, int k){ if(n==1)return k; long long prev=0,curr=k; long long ans = prev+curr; for(int i=2;i<=n;i++){ prev=curr; curr=(ans*(k-1))%M; ans=prev+curr; } return ans%M; } };

GFG | Problem of the day :

class Solution { public: int numSpecial(vector>& mat) { int m = mat.size(); int n = mat[0].size(); vector rowOne(m), colOne(n); for(int i = 0; i < m; i++) { rowOne[i] = accumulate(mat[i].begin(), mat[i].end(), 0); for(int j = 0; j < n; j++) { colOne[j] += mat[i][j]; } } int ans = 0; for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { ans += mat[i][j] == 1 && rowOne[i] == 1 && colOne[j] == 1; } } return ans; } };

LeetCode | Daily challenge :

class Solution{ public: // #define ll long long ll countStrings(int n) { vector<int>ones(n+1,0),zeros(n+1,0); int mod = 1e9 +7; ones[0]=1;ones[1]=1; zeros[0]=1;zeros[1]=2; for(int i=2;i<n;i++) { ones[i]=(ones[i-1]+ones[i-2])%mod; zeros[i]=(zeros[i-1]+zeros[i-2])%mod; } return (ones[n-1]+zeros[n-1])%mod; } };

GFG | Problem of the day :

class Solution { public: int maxProduct(vector& nums) { int m1 = 1; int m2 = 1; for(auto n : nums) { if(n>=m1) { if (n >= m2) swap (n ,m2); m1 = n; } } return(m1-1)*(m2-1); } };

LeetCode | Daily challenge :

class Solution{ public: int maxGold(int n, int m, vector> M) { vector> dp(n, vector(m, 0)); for (int i = 0; i < n; i++) { dp[i][0] = M[i][0]; } int ans = 0; for (int j = 1; j < m; j++) { for (int i = 0; i < n; i++) { int sum = 0, sum1 = 0, sum2 = 0; if (i > 0) { sum = dp[i - 1][j - 1]; } sum1 = dp[i][j - 1]; if (i < n - 1) { sum2 = dp[i + 1][j - 1]; } dp[i][j] = M[i][j] + max(sum, max(sum1, sum2)); ans = max(ans, dp[i][j]); } } return ans; } };

GFG | Problem of the day :

class Solution { public: int findSpecialInteger(vector& aa) { mapmp; int m=aa.size(); int mx=0,a; for(int i=0;im/4) { // a=it.second; mx=max(mx,it.first); } } cout<

LeetCode | Daily challenge :

class Solution{ public: long maximumSumSubarray(int K, vector &Arr , int N){ long maxi = 0; long sum = 0; int i=0; int j=0; while(j