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 minOperations(vector& nums) { unordered_map mp; int n= nums.size(); for(int i=0;i

LeetCode | Daily challenge :

class Solution { public: int singleElement(int arr[] ,int N) { sort(arr, arr + N); for(int i=0;i

GFG | Problem of the day :

class Solution { public: int numberOfBeams(vector& bank) { int ans=0; int prevCnt =0; int n =bank.size(),m=bank[0].size(); for(int i=0;i0){ // q.push(cnt); ans += prevCnt*cnt; prevCnt = cnt; }else{ continue; } } return ans; } };

LeetCode | Daily challenge :

class Solution { public: int smallestSubstring(string s) { int n = s.size() ; int i = 0 , j = 0 ; int zero = 0 , one = 0 , two = 0 ; int ans = INT_MAX; while(j <= n){ if(zero >= 1 && one >= 1 && two >= 1 ){ ans = min(ans , j - i) ; if(s[i] == '0') zero-- ; if(s[i] == '1') one-- ; if(s[i] == '2') two-- ; i++ ; } else{ if(s[j] == '0') zero++ ; if(s[j] == '1') one++ ; if(s[j] == '2') two++ ; j++ ; } } if(ans == INT_MAX) return -1 ; return ans ; } };

GFG | Problem of the day :

class Solution { public: vector> findMatrix(vector& nums) { setst; mapmp; for(int i=0;i>ans; for(int i=0;ix; for(auto it:st) { if(mp[it]!=0) { x.push_back(it); mp[it]--; } } if(x.size()) ans.push_back(x); } return ans; } };

LeetCode | Daily challenge :

class Solution{ public: long long int maxSumWithK(long long int a[], long long int n, long long int k) { long long int ans=0; long long int s=0; for(int i=0;i

GFG | Problem of the day :

class Solution { public: int findContentChildren(vector& g, vector& s) { sort(g.begin(),g.end()); sort(s.begin(),s.end()); int ans =0; int j=0; for(auto it: g){ while(j

LeetCode | Daily challenge :

class Solution { public: bool canPair(vector nums, int k) { vector mp(k, 0); int n = nums.size(); for(int i = 0; i < n; i++) mp[nums[i] % k]++; if(mp[0] % 2) return false; for(int i = 1; i < k; i++) { if(mp[i] != mp[k - i]) return false; } return true; } };

GFG | Problem of the day :

class Solution { public: int maxLengthBetweenEqualCharacters(string &s) { pair arr[27]; for(int i = 0;i<27;++i){ arr[i].first = -1; arr[i].second = -1; } int n = s.length(); for(int i = 0;i

LeetCode | Daily challenge :

class Solution { public: int isPossible(int n , int coins[]) { vector> dp(n + 1, vector(2025, -1)); if (solve(n, 2024, coins, dp)) return 1; for (int i = 1; 24*i <= 2024; i++) { if (solve(n, 24*i, coins, dp)) return 1; } for (int i = 1; 20*i <= 2024; i++) { if (solve(n, 20*i, coins, dp)) return 1; } return 0; } bool solve(int n, int sum, int coins[], vector> &dp) { if (sum == 0) return true; if (sum < 0 || n == 0) return false; if (dp[n][sum] != -1) return dp[n][sum]; // include int inc = solve(n - 1, sum - coins[n - 1], coins, dp); // exclude int exc = solve(n - 1, sum, coins, dp); return dp[n][sum] = inc || exc; } };