LeetCode, GeeksForGeeks Problem of the day solution @leetcode_gfg_potd Channel on Telegram

LeetCode, GeeksForGeeks Problem of the day solution

@leetcode_gfg_potd


Complete daily challenges from LeetCode, GeeksForGeeks and redeem their rewards

Channel link :
https://t.me/leetcode_gfg_potd

LeetCode, GeeksForGeeks Problem of the day solution (English)

Are you someone who loves a good challenge and enjoys solving problems? Look no further than the LeetCode, GeeksForGeeks Problem of the day solution channel! This channel is dedicated to providing you with daily challenges from LeetCode and GeeksForGeeks, two of the most popular platforms for coding practice and problem-solving.

Whether you are a seasoned coder looking to hone your skills or a beginner eager to learn and improve, this channel is perfect for you. Each day, you will be presented with a new problem to solve, giving you the opportunity to test your knowledge and problem-solving abilities. And the best part? You can redeem rewards for completing these challenges, adding an extra layer of motivation and excitement to your coding journey.

By joining the LeetCode, GeeksForGeeks Problem of the day solution channel, you will have access to a supportive community of like-minded individuals who share your passion for coding and problem-solving. You can exchange ideas, ask for help, and celebrate your successes together, making the learning process even more enjoyable and rewarding.

Don't miss out on this fantastic opportunity to challenge yourself, improve your coding skills, and earn rewards along the way. Join the LeetCode, GeeksForGeeks Problem of the day solution channel today by clicking on the link below:

Channel link :
https://t.me/leetcode_gfg_potd

LeetCode, GeeksForGeeks Problem of the day solution

08 Aug, 07:49


class Solution {
public:
vector<vector<int>> spiralMatrixIII(int rows, int cols, int rStart, int cStart) {
int m = rows;
int n = cols;
vector<vector<int>> ans;
vector<vector<int>> vis(m+n, vector<int>(m+n, 0));
int x = rStart;
int y = cStart;
int k = 1;
while(ans.size()<m*n){
// top row
for(int j = y; j<y+k; j++){
if(x>=0 && j>=0 && x<m && j<n && !vis[x][j]){
vis[x][j] = 1;
ans.push_back({x, j});
}
}
y+=k;
// right col
for(int i = x; i<x+k; i++){
if(i>=0 && y>=0 && i<m && y<n && !vis[i][y]){
vis[i][y] = 1;
ans.push_back({i, y});
}
}
x+=k;
k++;
//bottm row
for(int j = y; j>=y-k; j--){
if(x>=0 && j>=0 && x<m && j<n && !vis[x][j]){
vis[x][j] = 1;
ans.push_back({x, j});
}
}
y-=k;
// left col
for(int i = x; i>=x-k; i--){
if(i>=0 && y>=0 && i<m && y<n && !vis[i][y]){
vis[i][y] = 1;
ans.push_back({i, y});
}
}
x-=k;
k++;
}
return ans;
}
};

LeetCode, GeeksForGeeks Problem of the day solution

08 Aug, 07:49


LeetCode | Daily challenge :

LeetCode, GeeksForGeeks Problem of the day solution

08 Aug, 07:49


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;
}
};

LeetCode, GeeksForGeeks Problem of the day solution

08 Aug, 07:46


GFG | Problem of the day :

LeetCode, GeeksForGeeks Problem of the day solution

07 Aug, 13:58


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);
}
};

LeetCode, GeeksForGeeks Problem of the day solution

07 Aug, 13:58


LeetCode | Daily challenge :

LeetCode, GeeksForGeeks Problem of the day solution

07 Aug, 13:58


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++;
}

}
};

LeetCode, GeeksForGeeks Problem of the day solution

07 Aug, 13:57


GFG | Problem of the day :

LeetCode, GeeksForGeeks Problem of the day solution

06 Aug, 10:22


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;
}
};

LeetCode, GeeksForGeeks Problem of the day solution

06 Aug, 10:22


LeetCode | Daily challenge :

LeetCode, GeeksForGeeks Problem of the day solution

06 Aug, 10:19


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;
}
};

LeetCode, GeeksForGeeks Problem of the day solution

06 Aug, 10:19


GFG | Problem of the day :

LeetCode, GeeksForGeeks Problem of the day solution

05 Aug, 06:10


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;
}
};

LeetCode, GeeksForGeeks Problem of the day solution

05 Aug, 06:10


LeetCode | Daily challenge :

LeetCode, GeeksForGeeks Problem of the day solution

04 Aug, 22:31


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;
}
};

LeetCode, GeeksForGeeks Problem of the day solution

04 Aug, 22:30


GFG | Problem of the day :

LeetCode, GeeksForGeeks Problem of the day solution

04 Aug, 06:30


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;
}
};

LeetCode, GeeksForGeeks Problem of the day solution

04 Aug, 06:30


LeetCode | Daily challenge :

LeetCode, GeeksForGeeks Problem of the day solution

04 Aug, 06:30


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;
}
};

LeetCode, GeeksForGeeks Problem of the day solution

04 Aug, 06:30


GFG | Problem of the day :

1,349

subscribers

106

photos

0

videos