GEEKS FOR GEEKS SOLUTIONS🫢
Open in Telegram
1 342
Subscribers
No data24 hours
-27 days
-2930 days
Posts Archive
Still many of you don't know about the event, I will make video on this topic for New User through this event you will earn all the swags i am sharing
Aware of The Arcade Event ? (which provide google cloud swags)
class Solution{
public:
int goodSubtrees(Node *root,int k){
unordered_set s;
return DFS(root, k, s);
}
int DFS(Node* root, int k, unordered_set&s){
if(!root) return 0;
unordered_set s1, s2;
int lt = DFS(root->left, k, s1);
int rt = DFS(root->right, k, s2);
s = s1;
s.insert(s2.begin(), s2.end());
s.insert(root->data);
if(s.size() > k) return lt+rt;
else return lt+rt+1;
}
};
class Solution{
public:
int maxCoins(int n,vector> &ranges){
// Code here
sort(ranges.begin(),ranges.end());
vector> v(n);
int mx = 0;
for(int i= n-1;i>=0;i--)
{
mx = max(mx,ranges[i][2]);
v[i] = {ranges[i][0],mx};
}
int ans = 0;
for(int i=0;i p = {ranges[i][1],0};
auto it = lower_bound(v.begin()+i+1,v.end(),p) - v.begin();
if(it
class Solution{
public:
bool makePalindrome(int n,vector &arr){
// Code here
unordered_map mp;
for(auto i:arr)
{
mp[i]++;
}
int odd=0;
for(auto i: mp)
{
string temp=i.first;
reverse(temp.begin(),temp.end());
if(i.first==temp)
{
if(i.second%2) // odd
{
odd++;
}
if(odd>1)
{
return false;
}
}
else
{
if(i.second!=mp[temp])
{
return false;
}
}
}
return true;
}
};
class Solution{
public:
bool ispossible(vector<int> &sw,int k,long long mid)
{
int count = 0;
long long sum=0;
for(auto &it:sw)
{
sum+=it;
if(sum>=mid){
count++;
sum=0;
}
}
return count>=k+1;
}
int maxSweetness(vector<int>& sw, int n, int k) {
long long high = 0;
long long low = sw[0];
for(auto &it:sw)
{
high+=it;
low = min(low,(long long)it);
}
long long mid = 0;
while(low<=high)
{
mid = low + (high-low)/2;
if(ispossible(sw,k,mid)) low = mid+1;
else high = mid-1;
}
return low-1;
}
};
class Solution{
public:
map hmap;
string recurse(Node *node){
string p=to_string(node->data)+"#";
for(auto child:node->children){
p+=recurse(child);
}
hmap[p]++;
return p;
}
int duplicateSubtreeNaryTree(Node *root){
vector res;
recurse(root);
int ans=0;
for(auto x:hmap){
if(x.second>1) ans++;
}
return ans;
}
};
class Solution{
public:
int powerfullInteger(int n,vector> &i, int k) {
map mp ;
for(int j = 0 ; j < n ; j++){
mp[i[j][0]]++ ;
mp[i[j][1]+1]-- ;
}
int cnt = 0 , ans = -1 ;
for(auto &x : mp){
if(cnt >= k){
ans = max(ans , x.first - 1) ;
}
cnt += x.second ;
}
return ans ;
}
};
class Solution{
public:
long long findNumber(long long N){
char a[5]={'1','3','5','7','9'};
string s="";
long long pre=1,mul=5,times=2;
while(N>0){
long long temp=(N % mul)-1;
long long ind=(temp+mul)%mul;
int index=ind/pre;
s=a[index]+s;
N-=mul;
mul*=5;
pre*=5;
}
return stoll(s);
}
};
