en
Feedback
GeeksForGeeks - POTD | GFG POTD Answer

GeeksForGeeks - POTD | GFG POTD Answer

Closed channel

🚩 Channel was restricted by Telegram

Show more
1 218
Subscribers
No data24 hours
-97 days
-5730 days
Posts Archive
6th January : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer

class Solution { public: int primeFactors(int n) { vector a; while (n % 2 == 0) { a.push_back(2); n = n/2; } for (int i = 3; i <= sqrt(n); i = i + 2) { while (n % i == 0) { a.push_back(i); n = n/i; } } if (n > 2){ a.push_back(n); } return a.size(); } int sumOfPowers(int a, int b){ int c=0; for(int i=a;i<=b;i++){ c += primeFactors(i); } return c; } };

5th January : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer

class Solution{ public: int TotalWays(int N) { const int mod = 1000000007; long long prev = 1, curr = 1; for (int i = 0; i < N; ++i) { int temp = curr; curr = (prev + curr) % mod; prev = temp; } return ((curr % mod) * (curr % mod)) % mod; } };

4th January : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer

class Solution { public: int singleElement(int arr[] ,int N) { unordered_map mp; for (int i = 0; i < N; ++i) { mp[arr[i]]++; } for (auto i : mp) { if (i.second == 1) { return i.first; } } return -1; } };

3rd January : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer

class Solution { public: int smallestSubstring(string S) { int i = 0; int j = 0; int c[3] = {}; int n = S.size(); int result = 1e9; while(j <= n && i < n){ if(c[0] == 0 c[1] == 0 c[2] == 0) { c[S[j] -'0']++; j++; } else{ result = min(result, j-i); c[S[i] -'0']--; i++; } } if(result == 1e9) return -1; return result; } };

2nd January : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer

class Solution{ public: long long int maxSumWithK(long long int a[], long long int n, long long int k) { long long int ans = INT_MIN; long long int sum = 0; long long int last = 0; long long int j = 0; for(long long int i = 0; i < n; i++) { sum += a[i]; if(i - j + 1 == k) ans = max(ans, sum); else if(i - j + 1 > k) { last += a[j]; j++; if(last < 0) { sum -= last; last = 0; } ans = max(ans, sum); } } return ans; } };

1st January : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer

class Solution { public: bool canPair(vector nums, int k) { unordered_mapmp; for(int i=0;i

cout << "Happy New Year πŸŽ‡ 2⃣ 0️⃣ 2⃣ 4⃣!";

31st December : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer

class Solution { public: int isPossible(int n , int coins[]) { int sum = accumulate(coins, coins+n, 0); vector<bool> prev(sum+1, 0), cur(sum+1, 0); for(int totcoin=1; totcoin<=sum; ++totcoin) { prev[totcoin] = totcoin%20==0 totcoin%24==0 totcoin==2024; } for(int i=0; i<n; ++i) { for(int totcoin=0; totcoin<=sum; ++totcoin) { cur[totcoin] = prev[totcoin] || prev[totcoin+coins[i]]; } prev = cur; } return prev[0]; } };

30th December : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer

class Solution{ public: //Function to return the name of candidate that received maximum votes. vector < string > winner(string arr[], int n) { unordered_map < string, int > mp; int maxi = 0; vector < string > ans(2); for (int i = 0; i < n; i++) { mp[arr[i]]++; maxi = max(maxi, mp[arr[i]]); } for (auto it: mp) { if (it.second == maxi) { if (ans[0] == "") { ans[0] = it.first;; ans[1] = to_string(maxi); } if (ans[0] > it.first) ans[0] = it.first; } } return ans; } };

29th December : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer

class Solution{ public: int kSubstrConcat (int n, string s, int k) { if(n%k !=0) { return 0; } unordered_mapmp; for(int i=0;isecond==1) || (mp.begin()->second==(n/k)-1)) return true; return false; } };

28th December : C++ Solution☝🏼 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” πŸ™‹πŸ»β€β™‚οΈDiscussion ⁉️ Join βœ… @GFG_Answer