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

数据加载中...

吸引订阅者
十二月 '24
十二月 '24
+27
在0个频道中
十一月 '24
+65
在0个频道中
Get PRO
十月 '24
+47
在0个频道中
Get PRO
九月 '24
+47
在0个频道中
Get PRO
八月 '24
+62
在0个频道中
Get PRO
七月 '24
+58
在0个频道中
Get PRO
六月 '24
+93
在0个频道中
Get PRO
五月 '24
+87
在0个频道中
Get PRO
四月 '24
+79
在0个频道中
Get PRO
三月 '24
+56
在0个频道中
Get PRO
二月 '24
+29
在0个频道中
Get PRO
一月 '24
+53
在0个频道中
Get PRO
十二月 '23
+797
在0个频道中
日期
订阅者增长
提及
频道
21 十二月+5
20 十二月0
19 十二月+2
18 十二月0
17 十二月+2
16 十二月0
15 十二月+4
14 十二月0
13 十二月0
12 十二月0
11 十二月0
10 十二月+2
09 十二月0
08 十二月+3
07 十二月+1
06 十二月+1
05 十二月+1
04 十二月0
03 十二月0
02 十二月+4
01 十二月+2
频道帖子
class Solution { public: vector> spiralMatrixIII(int rows, int cols, int rStart, int cStart) { int m = rows; int n = cols; vector> ans; vector> vis(m+n, vector(m+n, 0)); int x = rStart; int y = cStart; int k = 1; while(ans.size()=0 && j>=0 && x=0 && y>=0 && i=y-k; j--){ if(x>=0 && j>=0 && x=x-k; i--){ if(i>=0 && y>=0 && i

2
LeetCode | Daily challenge :
521
3
class Solution { public: int f(Node* root){ if(root==NULL){ return 0; } if(root->left==NULL && root->right==NULL){ return root->data; } int val=f(root->left)+f(root->right); if(val==root->data){ return 2*val; } return -1; } bool isSumTree(Node* root) { if(root==NULL){ return true; } return f(root)==-1?false:true; } };
488
4
GFG | Problem of the day :
421
5
class Solution { public: string numberToWords(int n) { long long int limit = 1000000000000, curr , t = 0; if(n==0) return "Zero"; string multiplier[]={"","Trillion","Billion","Million","Thousand"}; string first20[]={"","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"}; string tens[] = {"","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"}; if(n<20){ return first20[n]; } string ans = ""; for(long long int i = n;i>0;i%=limit, limit /= 1000){ curr = i/limit; while(curr == 0){ i %= limit; limit /= 1000; curr = i/limit; ++t; } if(curr>99){ ans += (first20[curr/100] + " Hundred "); } curr = curr%100; if(curr>0 && curr<20){ ans += (first20[curr] + " "); } else if(curr%10==0 && curr!=0){ ans += (tens[curr/10-1] + " "); } else if(curr>20 && curr<100){ ans += (tens[curr/10-1] + " " + first20[curr%10] + " "); } if(t<4){ ans += (multiplier[++t] + " "); } } int l = ans.length(); return ans.substr(0,l-1); } };
398
6
LeetCode | Daily challenge :
251
7
class Solution { public: int kthElement(int k, vector<int>& arr1, vector<int>& arr2) { size_t m=arr1.size(); size_t n=arr2.size(); int i=0,j=0; int c=0; while (i<m && j<n){ if (arr1[i]<arr2[j]){ if ((c)==k-1) return arr1[i]; c++; i++; } else { if ((c)==k-1) return arr2[j]; c++; j++; } } //chk left out arrays while (i<m){ if ((c)==k-1) return arr1[i]; c++; i++; } while (j<n){ if ((c)==k-1) return arr2[j]; c++; j++; } } };
250
8
GFG | Problem of the day :
195
9
class Solution { public: int minimumPushes(string word) { int c[123] = { 0 }; for (unsigned int i = 0, len = word.length(); i < len; ++i) ++c[word[i]]; bool sorted = false; do { sorted = true; for (unsigned short i = 97; i < 122; ++i) if (c[i] < c[i + 1]) { int temp = c[i]; c[i] = c[i + 1]; c[i + 1] = temp; sorted = false; } } while (!sorted); int steps = 0, count = 0; for (unsigned short i = 97; i < 123; ++i) if (c[i] != 0) { steps += c[i] * (count / 8 + 1); ++count; } return steps; } };
227
10
LeetCode | Daily challenge :
171
11
class Solution { public: int isValid(string str) { int dot = 0; string temp = ""; for(int i = 0 ; i < str.length() ; i++){ if(str[i] == '.'){ dot++; if(temp.empty()) return false; else if(temp.size() > 1 && temp[0] == '0') return false; int num = stoi(temp); if(num < 0 || num > 256) return false; temp = ""; } else temp += str[i]; } if(temp.empty()) return false; else if(temp.size() > 1 && temp[0] == '0') return false; int num = stoi(temp); if(num < 0 || num > 256) return false; return dot == 3 ? true : false; } };
188
12
GFG | Problem of the day :
161
13
class Solution { public: string kthDistinct(vector<string>& arr, int k) { unordered_map<string,int> mp; string ans=""; for(int i=0;i<arr.size();i++){ mp[arr[i]]++; } for(int i=0;i<arr.size();i++){ if(mp[arr[i]]<2){ k--; } if(k<=0){ ans+=arr[i]; break; } } return ans; } };
192
14
LeetCode | Daily challenge :
150
15
class Solution { public: vector <int> bottomView(Node *root) { vector<int> res; if(root==NULL){ return res; } map<int, int> mp; queue<pair<Node* , int>> q; q.push({root, 0}); while(!q.empty()){ auto temp = q.front(); q.pop(); Node* node = temp.first; int vLine = temp.second; mp[vLine] = node->data; if(node->left){ q.push({node->left, vLine-1}); } if(node->right){ q.push({node->right, vLine+1}); } } for(auto i:mp){ res.push_back(i.second); } return res; } };
240
16
GFG | Problem of the day :
219
17
class Solution { public: int rangeSum(vector<int>& nums, int n, int left, int right) { vector<int> sub; long long MOD = 1e9 + 7; for (int i = 0; i < n; i++) { int sum = 0; for (int j = i; j < n; j++) { sum += nums[j]; sub.push_back(sum); } } sort(sub.begin(), sub.end()); long long totalSum = 0; for (int i = left - 1; i < right; i++) { totalSum = (totalSum + sub[i]) % MOD; } return totalSum; } };
286
18
LeetCode | Daily challenge :
186
19
class Solution { public: static bool compare(pair<int,int>&a,pair<int,int>&b){ if(a.second==b.second) return a.first<b.first; return a.second<b.second; } int maxMeetings(int n, int start[], int end[]) { vector<pair<int,int>>vec; for(int i=0;i<n;i++) vec.push_back({start[i],end[i]}); sort(vec.begin(),vec.end(),compare); int ans=1; int prev=0; for(int i=1;i<n;i++){ if(vec[i].first>vec[prev].second){ prev=i; ans++; } } return ans; } };
210
20
GFG | Problem of the day :
208