๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.59K subscribers
5.59K photos
3 videos
95 files
10.1K links
๐ŸšฉMain Group - @SuperExams
๐Ÿ“Job Updates - @FresherEarth

๐Ÿ”ฐAuthentic Coding Solutions(with Outputs)
โš ๏ธDaily Job Updates
โš ๏ธHackathon Updates & Solutions

Buy ads: https://telega.io/c/cs_algo
Download Telegram
long Count_sol (int N, vector<int> A, vector<int> B) {
   // Write your code here
   vector<long>dp(MAXN,0);
   unordered_map<int, int>f;
   unordered_map<int, int>g;
   for(int i=0;i<N;i++)
   {
    f[A[i]]++;
    g[B[i]]++;
   }
   long ans=0;
   for(int i=100000;i>=2;--i)
   {
    int c=0;
    int d=0;
    int s=0;
    for(int j=i;j<=100000;j+=i)
    {
        c+=f[j];
        d+=g[j];
        s+=dp[j];
    }
    long pw=(long)c*d;
    pw=pw-s;
    ans+=pw;
    dp[i]=pw;
   }
   return ans;
}

Count the Pairs โœ…
๐Ÿ‘Ž1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>

using namespace std;

int numIdleDrives(vector<int>& x, vector<int>& y) {
    int n = x.size();

    unordered_map<int, vector<int>> xMap, yMap;
    for (int i = 0; i < n; ++i) {
        xMap[y[i]].push_back(x[i]);
        yMap[x[i]].push_back(y[i]);
    }

    for (auto& pair : xMap) {
        sort(pair.second.begin(), pair.second.end());
    }

    for (auto& pair : yMap) {
        sort(pair.second.begin(), pair.second.end());
    }

    int count = 0;

    for (int i = 0; i < n; ++i) {
        int currX = x[i], currY = y[i];

        auto& yVec = xMap[currY];
        auto it1 = upper_bound(yVec.begin(), yVec.end(), currX);
        auto it2 = lower_bound(yVec.begin(), yVec.end(), currX);

        bool above = (it1 != yVec.end());
        bool below = (it2 != yVec.begin());

        auto& xVec = yMap[currX];
        it1 = upper_bound(xVec.begin(), xVec.end(), currY);
        it2 = lower_bound(xVec.begin(), xVec.end(), currY);

        bool left = (it1 != xVec.end());
        bool right = (it2 != xVec.begin());

        if (above && below && left && right) {
            count++;
        }
    }

    return count;
}

Amazon โœ…
from collections import defaultdict

def Parenting(N, U, Val, V):
    characters = Val
    n = len(characters)
    edges = [(U[i], V[i]) for i in range(len(U))]
    answer = [1 for _ in range(n)]
    adj = defaultdict(list)
   
    def recurse(node, parent):
        curr_char = characters[node]
        comp = [0 for _ in range(26)]
        comp[ord(curr_char) - ord('a')] += 1
        for node_ in adj[node]:
            if node_ != parent:
                comp = merge(comp, recurse(node_, node))
        answer[node] = comp[ord(curr_char) - ord('a')]
        return comp

    def merge(arr1, arr2):
        for i, el in enumerate(arr2):
            arr1[i] += el
        return arr1

    for x, y in edges:
        adj[x-1].append(y-1)
        adj[y-1].append(x-1)

    recurse(0, -1)
    return answer

Parent Node โœ…
int Arr_Diff (vector<int> arr) {
   // Write your code here
   int n=arr.size();
   int maxi=INT_MIN;
   int mini=INT_MAX;
   for(int i=0;i<n;i++)
   {
    if(arr[i]%2!=0)
    arr[i]=2*arr[i];
    maxi=max(maxi,arr[i]);
    mini=min(mini,arr[i]);
   }
   priority_queue<int>pq;
   for(int i=0;i<n;i++)
   {
    pq.push(arr[i]);
   }
   int min_dev=maxi-mini;
   int top=0;
   while(pq.top()%2==0)
   {
    top=pq.top();
    pq.pop();
    min_dev=min(min_dev,top-mini);
    mini=min(mini,top/2);
    pq.push(top/2);
   }
   top=pq.top();
   min_dev=min(min_dev,top-mini);
   return min_dev;
}

Array Difference โœ…
int solution (vector<int> chocolates, int M, int N) {
   // Find the maximum number of chocolates that can be selected.
   const int u=100005;
   long long int l[u];
   long long int ans=0;
   memset(l,-1,sizeof(l));
   l[0]=0;
   long long int s=0;
   for(int i=0;i<N;i++)
   {
    s+=chocolates[i];
    int tm=s%M;
    if(-1==l[tm])
    l[tm]=s;
    else
     ans=max(ans,s-l[tm]);
   }
   return static_cast<int>(ans/M);
}

Chocolate Distribution โœ…
๐Ÿ‘1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

int64_t findMax(vector<vector<int>>& items, int k) {
    int n = items.size() - 1;
    vector<vector<int64_t>> dp(n + 1, vector<int64_t>(k + 1, 0));
    vector<int> ult(n + 5, -1);

    // Sort the items based on their type (tp) in ascending order
    sort(items.begin() + 1, items.end());

    for (int i = 1; i <= n; i++) {
        int tp = items[i][0];
        int wt = items[i][1];
        int val = items[i][2];
        int lsttp = ult[tp];
        if (-1 == lsttp) lsttp = i - 1;
        for (int ow = 0; ow <= k; ow++) {
            dp[i][ow] = max(dp[i][ow], dp[i - 1][ow]);
            if (wt + ow <= k) {
                dp[i][wt + ow] = max({ dp[i][wt + ow], dp[lsttp][ow] + val, dp[i - 1][wt + ow] });
            }
        }
       
        if (-1 == ult[tp]) ult[tp] = i - 1;
    }

    int64_t res = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= k; j++) {
            res = max(res, dp[i][j]);
        }
    }

    return res;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> items(n + 1, vector<int>(3));
    for (int i = 1; i <= n; i++) {
        cin >> items[i][0] >> items[i][1] >> items[i][2];
    }

    int k;
    cin >> k;

    int64_t result = findMax(items, k);
    cout << result << endl;

    return 0;
}

Modified knapsack โœ…
๐Ÿ‘4
#include <vector>
#include <queue>
using namespace std;

int solve(vector<int> ropes) {
    priority_queue<int> pq(ropes.begin(), ropes.end());
    int ans = 0;
    while (pq.size() > 1) {
        int rope1 = pq.top();
        pq.pop();
        int rope2 = pq.top();
        pq.pop();
        if (rope1 < 2 || rope2 < 2) {
            break;
        }
        ans += (rope1 - 1) * (rope2 - 1);
    }
    return ans;
}

Ropes Pair Length โœ…
int solution(const string &s) {
    const int n = s.length();
    int r = 0;
    for (int i = n - 1, j = 0; i >= 0 && j < n; ++j) {
        if (s[i] == s[j]) {
            --i;
            ++r;
        }
    }
    return n - r;
}


Amazon โœ…
โค2
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
#include <bits/stdc++.h> #define ll long long using namespace std; vector<ll> count(ll k,vector<ll>& a) {     vector<ll> prime;     for (ll i=2;i<=sqrt(k);i++)     {         if (k%i==0)         {             prime.push_back(i);             while (k%i==0)โ€ฆ
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll count(ll k,vector<ll>& a)
{
    unordered_map<ll,ll>mpp,count;
    ll n=a.size();
    for (ll i=2;i*i<=(k);i++)
    {
        if (k%i==0)
          while(k%i==0) mpp[i]++,k/=i;
    }         
    if (k>1) mpp[k]++;
    for (auto num:a)
    {
        for(auto it:mpp)
        {
            ll fac=it.first;
            while (num%fac==0)
            {
                count[fac]++;
                num/=fac;
            }
        }
    }
    ll mini=LONG_MAX;
    for(auto&it:count)
      {
        it.second/=mpp[it.first];
        mini=min(mini,it.second);
      }
      return (mini==LONG_MAX)?0:min(n,mini);
}
signed main() {
    ll n, k; cin>>n>>k;
    vector<ll>a(n);
    for(ll i=0;i<n;i++) cin>>a[i];
    cout<<min(n,count(k,a));
    return 0;
}

K Divisible number โœ…
๐Ÿ‘1
#include<bits/stdc++.h>
using namespace std;
int N,M;
int findMinimum (vector<vector<vector<int>>>&arr,int rr,int cc) {
   // Write your code here
   vector<vector<bool>>seen(arr.size(),vector<bool>(arr[0].size(),false));
   seen[0][0]=true;
   queue<pair<int,int>>q;
   int le=0;
   q.push({0,0});
   while(!q.empty())
   {
    int si=q.size();
    while(si-->0)
    {
        pair<int,int>cu=q.front();
        q.pop();
        int r=cu.first;
        int c=cu.second;
        if(r==rr and c==cc)
        return le;
        int x=arr[r][c][0];
        int y=arr[r][c][1];
        int rc=arr.size();
        int cd=arr[0].size();
        int dir[8][2]={{x,y},{x,-y},{-x,y},{-x,-y},{y,x},{y,-x},{-y,x},{-y,-x}};
        for(int i=0;i<8;i++)
        {
            int nr=r+dir[i][0];
            int nc=c+dir[i][1];
            if(nr>=0 and nr<rc and nc>=0 and nc<cd and !seen[nr][nc])
            {
                q.push({nr,nc});
                seen[nr][nc]=true;
            }
        }
    }
    le++;
   }
   return -1;
}

int main() {

    ios::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin >> T;
    for(int t_i=0; t_i<T; t_i++)
    {
        //int N;
        cin >> N;
        //int M;
        cin >> M;
        vector<vector<vector<int>>>arr(N,vector<vector<int>>(M,vector<int>(2)));
        for(int i=0;i<N;i++)
        {
            for(int j=0;j<M;j++)
            {
                cin>>arr[i][j][0]>>arr[i][j][1];
            }
        }
        int out_;
        out_ = findMinimum(arr,N-1,M-1);
        cout << out_;
        cout << "\n";
    }
}

Minimum moves โœ…
Hackerearth
๐Ÿ‘2
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
#include <bits/stdc++.h> #define ll long long using namespace std; vector<ll> count(ll k,vector<ll>& a) {     vector<ll> prime;     for (ll i=2;i<=sqrt(k);i++)     {         if (k%i==0)         {             prime.push_back(i);             while (k%i==0)โ€ฆ
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll count(ll k,vector<ll>& a)
{
    unordered_map<ll,ll>mpp,count;
    ll n=a.size();
    for (ll i=2;i*i<=(k);i++)
    {
        if (k%i==0)
          while(k%i==0) mpp[i]++,k/=i;
    }         
    if (k>1) mpp[k]++;
    for (auto num:a)
    {
        for(auto it:mpp)
        {
            ll fac=it.first;
            while (num%fac==0)
            {
                count[fac]++;
                num/=fac;
            }
        }
    }
    ll mini=LONG_MAX;
    for(auto&it:count)
      {
        it.second/=mpp[it.first];
        mini=min(mini,it.second);
      }
      return (mini==LONG_MAX)?0:min(n,mini);
}
signed main() {
    ll n, k; cin>>n>>k;
    vector<ll>a(n);
    for(ll i=0;i<n;i++) cin>>a[i];
    cout<<min(n,count(k,a));
    return 0;
}


K divisible number โœ…
#include <bits/stdc++.h>
using namespace std;

const int MOD = 1000000007;

long long countMaxXOR(int N, int K) {
    vector<vector<long long>> dp(N + 1, vector<long long>((1 << K), 0));
    dp[1][0] = 1;

    for (int i = 2; i <= N; i++) {
        for (int j = 0; j < (1 << K); j++) {
            for (int k = 0; k < (1 << K); k++) {
                if ((j ^ k) > j) {
                    dp[i][j ^ k] = (dp[i][j ^ k] + dp[i - 1][j]) % MOD;
                }
            }
        }
    }

    long long total_count = 0;
    for (int j = 0; j < (1 << K); j++) {
        total_count = (total_count + dp[N][j]) % MOD;
    }

    return total_count;
}

Array Construction โœ…
๐Ÿ‘1
Greetings from Tata Strive- Nagavara Centre- Bengaluru

๐ŸŒŸ Empowering Students for Brighter Futures ๐ŸŒŸ

๐Ÿš€ Join our targeted upskilling initiatives! ๐Ÿš€

Are you ready to take your future to new heights? We're offering exclusive courses in AWS Restart, Cyber Security & GIS and Drone Data Processing, Food and Beverages Steward, Housekeeping attendant to uplift underprivileged students like you. Here's your chance to unlock a world of opportunities!

๐ŸŽ“ Course Details:

1.  AWS Restart
๐Ÿ“œ Eligibility Criteria:
โ€ข Education- BE/Btech(CS,IT,IS)/MCA
โ€ข Year of passing -2021,22,23
โ€ข Score- min 60% score in 10th, 12th and graduation

2.  Cyber Security
๐Ÿ“œ Eligibility Criteria:
โ€ข Education- BE/Btech(CS,IT,IS)/MCA
โ€ข Year of passing -2021,22,23
โ€ข Score- min 60% score in 10th, 12th and graduation

3.  Geographic Information Systems (GIS) and Drone Data Processing
๐Ÿ“œ Eligibility Criteria:
โ€ข Education- 10th Pass. Diploma and ITI Pass are highly preferred.
โ€ข Proficiency in reading and writing English/Hindi

4. Food & Beverages Steward
๐Ÿ“œ Eligibility Criteria:
โ€ข Education- 10th Pass & Above
โ€ข Interested in Food Industry

5. Housekeeping Attendant
๐Ÿ“œ Eligibility Criteria:
โ€ข Education- 8th & Above
โ€ข Interested in Hospitality

๐ŸŒˆ Why Choose Us?:

Hands-on training from industry experts
Learn cutting-edge skills in high-demand fields
Assistance for placements and internships
Empower yourself for a brighter tomorrow!
๐Ÿ“… Enrollment Period: Limited seats available! Act fast to secure your spot.

๐Ÿ“ How to Apply:
๏ถ Register now for Cyber Security, AWS & GIS Drone Courses: https://docs.google.com/forms/d/e/1FAIpQLScJNaCZVbTWr3FT6MpPjT9XjLu637pCXDMbcrY04cQzS1gRUQ/viewform?usp=sf_link

๏ถ Register now for F&B and Housekeeping attendant Courses
        https://forms.gle/Z58jZLqQ2Uzw29j76
Don't let this opportunity pass you by. Take the first step towards a brighter future today! ๐Ÿ’ซ

๐Ÿ“ฒ Contact Us:
Mahesha KC:  9449941568
Let's journey towards success together!
๐Ÿ‘1