๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.52K subscribers
5.56K photos
3 videos
95 files
9.7K 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
vector<string> solve(vector<string> s, vector<string> a) {
    vector<string> r;
    for (auto& song : s) {
        string sn;
        int sl;
        istringstream ss(song);
        getline(ss, sn, ':');
        ss >> sl;

        for (auto& anim : a) {
            string an;
            int al;
            istringstream as(anim);
            getline(as, an, '/');
            as >> al;

            if (sl % al == 0) {
                r.push_back(an + ":" + to_string(sl / al));
                break;
            }
        }
    }
    return r;
}

Tradedesk โœ…
import java.util.*;
public class Main {
    public int solution(int[] A, int X, int Y) {
        if (A == null || A.length < 1) return 0;
        Arrays.sort(A);
        int r = Integer.MAX_VALUE;
        for (int i = 0, j = 0, left = 0, right = 0;;) {
            for (; j < A.length - i && (left + A[j]) <= right; left += A[j++])
            ;
            r = Math.min(r, X * Math.max(A.length - j - i, 0) + Y * i);
            if (++i > A.length) break;
            right += A[A.length - i];
           
        }
        return r;
    }

Tradedesk โœ…
void solve(vector<ll> a,ll l ,ll r){
   set<pair<ll,ll>>s;
   map<ll,ll>m;
   ll i=0;
   ll ans=INT_MAX;
   for(auto x:a){
      
       if(x<l || x>r){
           i++;
           continue;
       }
       else{
           if(m.find(x)==m.end()){
               m[x]=i;
               s.insert({i,x});
           }
           else{
               s.erase({m[x],x});
               s.insert({i,x});
               m[x]=i;
           }
       }
       //cout<<i<<" "<<m.size()<<endl;
       if(m.size()==r-l+1){
           auto it=s.begin();
         
           ans=min(ans,i-(*s.begin()).first+1);
       }
       i++;
   }
   cout<<(ans==INT_MAX?-1:ans)<<endl;
}

Tradedesk โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
def getMaximumLength(lotteryID, winnerID, k):
    m, n = len(lotteryID), len(winnerID)

    dp = [[[0] * n for _ in range(m)] for _ in range(k + 1)]

    for o in range(k + 1):
        for i in range(m):
            for j in range(n):
                c1, c2 = lotteryID[i], winnerID[j]
                abs_diff = abs(ord(c1) - ord(c2))
                diff = (26 - abs_diff if abs_diff > 13 else abs_diff)
               
                if o > 0:
                    dp[o][i][j] = max(dp[o][i][j], dp[o - 1][i][j])
                if i > 0:
                    dp[o][i][j] = max(dp[o][i][j], dp[o][i - 1][j])
                if j > 0:
                    dp[o][i][j] = max(dp[o][i][j], dp[o][i][j - 1])
                if o - diff >= 0:
                    if i > 0 and j > 0:
                        dp[o][i][j] = max(dp[o][i][j], dp[o - diff][i - 1][j - 1] + 1)
                    else:
                        dp[o][i][j] = 1 # if i or j==0 and it is possible to use a move then string can only match 1 char

    return dp[k][m - 1][n - 1]

Source : Winner โœ…
vector<int> getNetProfit(vector<string> e) {
    unordered_map<string, int> p;
    unordered_map<string, int> q;
    vector<int> r;
    int b = 0;

    for (const auto& v : e) {
        istringstream i(v);
        string a, s;
        int x;
        i >> a >> s >> x;

        if (a == "BUY") {
            b -= p[s] * x;
            q[s] += x;
        } else if (a == "SELL") {
            b += p[s] * x;
            q[s] -= x;
        } else if (a == "CHANGE") {
            b += q[s] * x;
            p[s] += x;
        } else if (a == "QUERY") {
            r.push_back(b);
        }
    }

    return r;
}

Source : Hola โœ…
bool isMatch(string& text, string& pat) {
    int textLen = text.length();
    int patLen = pat.length();

    if (patLen != textLen) {
        return false;
    }

    for (int i = 0; i < textLen; ++i) {
        if (pat[i] != '*' && pat[i] != text[i]) {
            return false;
        }
    }

    return true;
}

vector<string> matchStrings(vector<string> text, vector<string> pat) {
    vector<string> result;

    for (int i = 0; i < text.size(); ++i) {
        if (isMatch(text[i], pat[i])) {
            result.push_back("YES");
        } else {
            result.push_back("NO");
        }
    }

    return result;
}

//Amazon Qs 1โœ…
int solve(vector<int> a, vector<int> b) {
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    int c = 0;
    for (int i = 0; i < a.size(); i++) {
        c += abs(a[i] - b[i]);
    }

    return c;
}

Amazon โœ