๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

long getkRepValue(string user_history, long k) {
    long n = user_history.size();
    unordered_map<char, long> count;
    long left = 0, right = 0, ans = 0;

    while (right < n) {
        count[user_history[right]]++;
        while (count[user_history[right]] >= k && left <= right) {
            ans += n - right;
            count[user_history[left]]--;
            left++;
        }
        right++;
    }

    return ans;


Machine learning Amazon โœ…
int solve(vector<int> tc) {
    int n = tc.size();
    vector<int> p(n), s(n);

    p[0] = tc[0];
    for (int i = 1; i < n; ++i) {
        p[i] = p[i - 1] + tc[i];
    }

    s[n - 1] = tc[n - 1];
    for (int i = n - 2; i >= 0; --i) {
        s[i] = s[i + 1] + tc[i];
    }

    int m = max(p[0], s[0]);
    for (int i = 1; i < n; ++i) {
        m = max(m, max(p[i], s[i]));
    }

    return m;
}

Amazon โœ…
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 โœ