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: vector findArray(vector& pref) { vector arr; arr.push_back(pref[0]); for(int i = 1; i

LeetCode | Daily challenge :

class Solution{ public: void pushZerosToEnd(int arr[], int n) { vectorv; int count=0; for(int i=0;i

GFG | Problem of the day :

class Solution { public: static int compare(int a, int b){ int v1 = __builtin_popcount(a); int v2 = __builtin_popcount(b); if(v1 != v2) return v1 sortByBits(vector& arr) { sort(arr.begin(), arr.end(), compare); return arr; } };

LeetCode | Daily challenge :

class Solution{ public: // Returns sum of bitwise OR // of all pairs long long int sumXOR(int arr[], int n) { vectorv(31,0); long long int ans=0; for(int i=0;i

GFG | Problem of the day :

class Solution { public: int poorPigs(int buckets, int minutesToDie, int minutesToTest) { int periods = minutesToTest/minutesToDie; return ceil(log2(buckets) / log2(periods+1)); } };

LeetCode | Daily challenge :

class Solution { public: // Function to check if Kth bit is set or not. bool checkKthBit(int n, int k) { return (n&(1<

GFG | Problem of the day :

class Solution { private: int mod = 1000000007; unordered_map > mp; public: int vowelPermutations(int n, int i, char prev, vector >& dp){ if(i>n){ return 0; } if(i==n){ switch(prev){ case 'a': return 1; break; case 'e': return 2; break; case 'i': return 4; break; case 'o': return 2; break; case 'u': return 1; break; default: return 5; } } int index = prev - 'a'; if(dp[i][index] != -1){ return dp[i][index]; } long long result = 0; for(auto next:mp[prev]){ result += vowelPermutations(n, i+1, next, dp); } dp[i][index] = result%mod; return dp[i][index]; } int countVowelPermutation(int n) { mp['b'] = {'a', 'e','i','o', 'u'}; mp['a'] = {'e'}; mp['e'] = {'a','i'}; mp['i'] = {'a', 'e', 'o', 'u'}; mp['o'] = {'i','u'}; mp['u'] = {'a'}; vector > dp(n+2, vector(27, -1)); int len = 1; char prev = 'b'; return vowelPermutations(n, len, prev, dp); } };

LeetCode | Daily challenge :

class Solution { public: int is_bleak(int n) { for(int i=0;i<32 and i<=n;i++) { if(__builtin_popcount(n-i)==i) return 0; } return 1; } };

GFG | Problem of the day :

class Solution { public: string expand(int s, int e, string& str){ while(s>=0 && elg.size()){ lg = odd; } } return lg; } };

LeetCode | Daily challenge :

class Solution{ public: int minimumNumberOfDeletions(string s) { int n = s.size(); vector> dp(n + 1,vector(n + 1,-1)); string s2 = s; reverse(s2.begin(),s2.end()); int lps = solve(s2,s,dp,n,n); return s.size() - lps; } int solve(string &s2,string &s1,vector> &dp,int n1,int n2){ if(n1==0 or n2==0){ return 0; } if(dp[n1][n2]!=-1){ return dp[n1][n2]; } if(s1[n1 - 1]==s2[n2 - 1]){ return dp[n1][n2] = 1 + solve(s2,s1,dp,n1 - 1,n2 - 1); } return dp[n1][n2] = max(solve(s2,s1,dp,n1 - 1,n2),solve(s2,s1,dp,n1,n2 - 1)); } };