ar
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 rec(int i,string &s,int n,vector&dp) { if(i==n) { return 1; } if(dp[i]!=-1) return dp[i]; if(s[i]=='0') return 0; int cnt=0; //taking one digit if(s[i]!='0') cnt+=rec(i+1,s,n,dp); //taking 2 digits along with conditions if(idp(n+1,-1); int ans=rec(0,s,n,dp); return ans; } };

LeetCode | Daily challenge :

class Solution { public: //Function for finding determinant of matrix. int determinantOfMatrix(vector > matrix, int n) { if(n == 1) return matrix[0][0]; if(n == 2) return matrix[0][0] * matrix[1][1] - matrix[1][0] * matrix[0][1]; int det = 0; for(int i = 0, sign = 1; i < n; i++, sign = -sign){ vector> small_matrix(n-1, vector(n-1)); int a = 0; for(int j = 0; j < n; j++){ if(j == i) continue; for(int k = 1; k < n; k++) small_matrix[k-1][a] = matrix[k][j]; a++; } det += sign * matrix[0][i] * determinantOfMatrix(small_matrix, n-1); } return det; } };

GFG | Problem of the day :

class Solution { public: int minOperations(string s) { int count0= 0; int count1= 0; for(int i= 0; i< s.length(); i++){ if(i%2== 0 && s[i]== '0'){ count1++; }else if(i%2== 1 && s[i]== '1'){ count1++; } } for(int i= 0; i< s.length(); i++){ if(i%2== 0 && s[i]== '1'){ count0++; }else if(i%2== 1 && s[i]== '0'){ count0++; } } return min(count1, count0); } };

LeetCode | Daily challenge :

class Solution { public: int buyMaximumProducts(int n, int k, int price[]){ vector> v; int cnt=0, tmp; for(int i=0; i=0){ if(k

GFG | Problem of the day :

class Solution { public: bool isPathCrossing(string path) { unordered_set visited; visited.insert("0,0"); int x = 0, y = 0; for (char direction : path) { if (direction == 'N') y++; else if (direction == 'S') y--; else if (direction == 'E') x++; else if (direction == 'W') x--; string currentPosition = to_string(x) + "," + to_string(y); if (visited.find(currentPosition) != visited.end()) { return true; } visited.insert(currentPosition); } return false; } };

LeetCode | Daily challenge :

class Solution { public: //Function to find all elements in array that appear more than n/k times. int countOccurence(int arr[], int n, int k) { int count=0; unordered_mapmp; for(int i=0;in/k){ count++; } } return count; } };

GFG | Problem of the day :

class Solution { public: int maxScore(string s) { int ans = INT_MIN; for(int i=0; i

LeetCode | Daily challenge :

class Solution{ public: static bool cmp(vector& a,vector& b) { if(a[1]!=b[1]) return a[1] maxMeetings(int N,vector &S,vector &F){ vector> v; for(int i=0;i ans; ans.push_back(v[0][2]); int pre=v[0][1]; for(int i=1;ipre) { ans.push_back(v[i][2]); pre=v[i][1]; } } sort(ans.begin(),ans.end()); return ans; } };

GFG | Problem of the day :

class Solution { public: int maxWidthOfVerticalArea(vector>& points) { int n=points.size(); sort(points.begin(),points.end()); int res=0; for(int i=0;i

LeetCode | Daily challenge :

class Solution { public: int minCandy(int N, vector &ratings) { vector candy(N,1); for(int i = 1; iratings[i-1]) candy[i] = candy[i-1] + 1; else{ int j = i; while(j>0 && candy[j]>=candy[j-1] && ratings[j]