ru
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: string removeDuplicateLetters(string s) { int n=s.size(); string result; vectorlastindex(26); vectortaken(26,false); for(int i=0;i0 and result.back()>ch and lastindex[result.back()-'a']>i){ taken[result.back()-'a']=false; result.pop_back(); } result.push_back(ch); taken[idx]=true; } return result; } };

LeetCode | Daily challenge :

class Solution{ public: // arr[] : int input array of integers // k : the quadruple sum required vector > fourSum(vector &arr, int k) { int n=arr.size(); vector >res; sort(arr.begin(),arr.end()); for(int i=0;i0 and arr[i]==arr[i-1]) continue; for(int j=i+1;ji+1 and arr[j]==arr[j-1]) continue; int l=j+1; int r=n-1; while(r>l) { if(arr[i]+arr[j]+arr[l]+arr[r]==k) { res.push_back({arr[i],arr[j],arr[l],arr[r]}); l++;r--; while(lk) r--; else l++; } } } return res; } };

GFG | Problem of the day :

class Solution { public: char findTheDifference(string s, string t) { int ans=t[t.length()-1]; for(int i=0;i

LeetCode | Daily challenge :

class Solution { public: vector<int> maxCombinations(int N, int K, vector<int> &A, vector<int> &B) { // code here sort(A.begin(),A.end()); sort(B.begin(),B.end()); vector<int>ans; priority_queue<pair<int,int>>pq; for(int i=0;i<N;i++) { int sum = A[i]+B[N-1]; pq.push({sum,N-1}); } while(!pq.empty() and K--) { int sum = pq.top().first; int idx = pq.top().second; pq.pop(); ans.push_back(sum); if(idx-1>=0) pq.push({sum-B[idx]+B[idx-1], idx-1}); } return ans; } };

GFG | Problem of the day :

class Solution { public: double champagneTower(int poured, int query_row, int query_glass) { if (poured==0) return 0; vector<double> row(1, poured); for(int i=0; i<query_row; i++){ vector<double> next(i+2, 0); for(int j=0; j<=i; j++){ if (row[j]<=1) continue; double excess=(row[j]-1)/2.0; next[j]+= excess; next[j+1]+= excess; } row=next; } return min(1.0, row[query_glass]); } };

LeetCode | Daily challenge :

class Solution{ public: vector duplicates(int arr[], int n) { vectorv; int flag = 0; sort(arr,arr+n); for(int i=0; i 0) return v; return {-1}; } };

GFG | Problem of the day :

class Solution { public: static bool compare(string &s1,string &s2){ return s1.size() < s2.size(); } bool isPredecessor(string s1, string s2){ if(s1.length() + 1 == s2.length()){ int count = 0; int k = 0; char c = s1[0]; for(int i = 0; i1){ return false; } } } return true; } return false; } int longestStrChain(vector& words) { sort(words.begin(), words.end(), compare); int start = 0; int end = 1; int maxCount = 1; map m; for(int i = 0;i

LeetCode | Daily challenge :

class Solution{ public: // Function to find equilibrium point in the array. // a: input array // n: size of array int equilibriumPoint(long long a[], int n) { long long sum=0; long long crsum=0; for(int i=0;i

GFG | Problem of the day :

class Solution { public: bool isSubsequence(string s, string t) { int i=0; int j=0; int n1=s.size(); int n2=t.size(); while(i

LeetCode | Daily challenge :

class Solution { public: vector<int> find(int arr[], int n , int x ) { int s = 0; int e=n-1; //vector<int> ans; int first = -1; while(s<=e){ int mid = s + (e-s)/2; if(arr[mid]==x){ first = mid; e = mid - 1; } else if(arr[mid]>x){ e = mid -1; } else{ s = mid +1; } } s = 0; e = n-1; int last = -1; while(s<=e){ int mid = s + (e-s)/2; if(arr[mid]==x){ last = mid; s = mid + 1; } else if(arr[mid]>x){ e = mid -1; } else{ s = mid + 1; } } return {first, last}; } };