๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.63K subscribers
5.61K photos
3 videos
95 files
10.6K 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
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
Geek Countโœ…


const int MOD = 1000000007;

int countGeekSubsequences(const string& s) {
    int n = s.length();
    vector<vector<int>> dp(5, vector<int>(n + 1, 0));
    for (int i = 0; i < 5; ++i)
        dp[i][0] = 0;
    for (int i = 0; i <= n; ++i)
        dp[0][i] = 1;

    for (int i = 1; i <= 4; ++i) {
        for (int j = 1; j <= n; ++j) {
            dp[i][j] = dp[i][j - 1];
            if (s[j - 1] == "geek"[i - 1])
                dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % MOD;
        }
    }
    
    return dp[4][n];
}
๐Ÿ˜1
#include <vector>
#include <unordered_map>
#include <iostream>

using namespace std;

int getMinTransactions(int n, vector<vector<int>>& debt) {
    unordered_map<int, int> balance
    for (const auto& d : debt) {
        balance[d[0]] -= d[2];
        balance[d[1]] += d[2];
    }
   
    vector<int> transactions;
    for (const auto& entry : balance) {
        if (entry.second != 0) {
            transactions.push_back(entry.second);
        }
    }

    int count = 0;
    int i = 0, j = transactions.size() - 1;
    while (i < j) {
        if (transactions[i] + transactions[j] == 0) {
            count++;
            i++;
            j--;
        } else if (transactions[i] + transactions[j] > 0) {
            transactions[i] += transactions[j];
            j--;
            count++;
        } else {
            transactions[j] += transactions[i];
            i++;
            count++;
        }
    }
    return count;
}

Transaction Simplification โœ