ch
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 buyChoco(vector& prices, int money) { int m1 = INT_MAX; int m2 = INT_MAX; int temp=-1; for(int i=0;iprices[i]){ m1 = prices[i]; temp = i; } } for(int i=0;i=0){ return money-m1-m2; } return money; } };

LeetCode | Daily challenge :

class Solution{ public: int findWinner(int n, int A[]){ int result = accumulate(A, A+n, 0, bit_xor()); return result!=0 && n&1?2:1; } };

GFG | Problem of the day :

class Solution { public: int dr[8]={-1, -1, -1, 0, 0, 1, 1, 1}; int dc[8]={-1, 0, 1, -1, 1, -1, 0, 1}; int n, m; int avg(int row, int col, vector>&img){ int cnt=1; int sum=img[row][col]; for(int i=0; i<8; i++){ int nr=row+dr[i]; int nc=col+dc[i]; if(nr>=0 && nr=0 && nc> imageSmoother(vector>& img) { n=img.size(); m=img[0].size(); vector>ans(n, vector(m, 0)); for(int i=0; i

LeetCode | Daily challenge :

class Solution { public: //Function to find the first position with different bits. int posOfRightMostDiffBit(int m, int n) { if(m==n) return -1; int cnt=1; while(n>0 && m>0) { if((n&1)!=(m&1)) return cnt; cnt++; n>>=1; m>>=1; } return cnt; } };

GFG | Problem of the day :

class Solution { public: int maxProductDifference(vector& nums) { sort(nums.begin(),nums.end()); int n= nums.size()-1; int result= nums[n] *nums[n-1]-nums[0]*nums[1]; return result; } };

LeetCode | Daily challenge :

class Solution { public: int gameOfXor(int n, int A[]) { int ans = 0; for(int i=0; i

GFG | Problem of the day :

class FoodRatings { public: struct comparator{ bool operator()(const pair& F1 , const pair& F2)const{ return F1.second > F2.second || (F1.second == F2.second && F1 < F2); } }; unordered_map,comparator>> CF; unordered_map FC; unordered_map FR; FoodRatings(vector& foods, vector& cuisines, vector& ratings) { for(int i = 0; ifirst; } };

LeetCode | Daily challenge :

class Solution{ public: // calculate the maximum sum with out adjacent int findMaxSum(int *arr, int n) { int a0=0,a1=arr[0]; for(int i=1;i

GFG | Problem of the day :

class Solution { public: bool isAnagram(string s, string t) { if (s.length() != t.length()) return false; int n = s.length(); int counts[26] = {0}; for (int i = 0; i < n; i++) { counts[s[i] - 'a']++; } for (int i = 0; i < n; i++) { counts[t[i] - 'a']--; } for (int i = 0; i < 26; i++) if (counts[i]) return false; return true; } };

LeetCode | Daily challenge :

long long int countStr(long long int n){ return 1 + 2*n + n*(n-1)*(n+1)/2; }