๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.61K subscribers
5.59K photos
3 videos
95 files
10.2K 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 <iostream>
#include <unordered_map>
#include <vector>
#include <string>
using namespace std;
vector<string> rateLimiter(vector<string>& requests, vector<int>& timestamps) {
    unordered_map<string, vector<int>> domainRequests;
    vector<string> result;
   
    for (int i = 0; i < requests.size(); i++) {
        string domain = requests[i];
        int time = timestamps[i];
        vector<int>& reqs = domainRequests[domain]; 
        vector<int> last30;
        for (int t : reqs) {
            if (time - t <= 30) {
                last30.push_back(t);
            }
        }
                vector<int> last5;
        for (int t : last30) {
            if (time - t <= 5) {
                last5.push_back(t);
            }
        }

        if (last5.size() >= 2) {
            result.push_back("{status: 429, message: Too many requests}");
        } else if (last30.size() >= 5) {
            result.push_back("{status: 429, message: Too many requests}");
        } else {
            result.push_back("{status: 200, message: OK}");
            last30.push_back(time);
        }
       
        domainRequests[domain] = last30;
    }
   
    return result;
}


Twilio โœ…
#include <iostream>
#include <vector>
using namespace std;

bool hasConsecutiveOnes(int num) {
    return (num & (num >> 1)) != 0;
}

int solve(int p) {
    if (!hasConsecutiveOnes(p)) {
        return p;
    }

    int mask = 1;

    for (int i = 30; i >= 0; --i) {
        int bit_i = (p >> i) & 1;
        int bit_i_next = (p >> (i + 1)) & 1;

        if (bit_i == 1 && bit_i_next == 1) {
            mask = (1 << (i + 1)) - 1;
            p = (p & ~mask) + (1 << (i + 1));
            break;
        }
    }

    return solve(p);
}

int main() {
     int t;
    cin >> t;
      while (t--) {
    int p;
    cin >> p;
   
    cout << solve(p) << endl;
      }
    return 0;
}


AMD โœ…
โค1
async function pulseRate(diagnosisName, doctorId) {
    const apiUrl = 'https://jsonmock.hackerrank.com/api/medical_records';
    let currentPage = 1;
    let totalPages = 1;
    let sumPulseRate = 0;
    let totalCount = 0;

    do {
        const response = await fetch(${apiUrl}?page=${currentPage});
        const data = await response.json();

       
        totalCount = data.total;
        totalPages = data.total_pages;

       
        const records = data.data || [];
        sumPulseRate += records.reduce((acc, record) => acc + record.vitals.pulse, 0);

       
        currentPage++;
    } while (currentPage <= totalPages);

   
    const averagePulseRate = Math.trunc(sumPulseRate / totalCount);

    return averagePulseRate;
}
โค1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <bits/stdc++.h> 
using namespace std;
#define ll long long
map<string, map<string, ll>> user;
map<string, ll> users;
set<string> banks;
vector<string> split(const string &s) {
    stringstream ss(s);
    vector<string> result;
    string token;

    while (getline(ss, token, ',')) {
        result.push_back(token);
    }
    return result;
}
void init(string &s) {
    vector<string> bankers = split(s);
    ll balance = stoll(bankers[2]);
    users[bankers[1]] = balance;
    for (int i = 3; i < bankers.size(); i++) {
        user[bankers[1]].insert({bankers[i], balance});
        banks.insert(bankers[i]);
    }
}
string post(string &s) {
    vector<string> help = split(s);
    ll value = stoll(help[4]);
   
    if (banks.find(help[2]) != banks.end() && banks.find(help[3]) != banks.end())
        return "FAILURE";
   
    if (banks.find(help[3]) != banks.end()) {
        if (users.find(help[2]) == users.end()) return "FAILURE";
        if (user[help[2]].find(help[3]) == user[help[2]].end()) return "FAILURE";
        if (users[help[2]] < value) return "FAILURE";
        users[help[2]] -= value;
        return "SUCCESS";
    }
   
    if (banks.find(help[2]) != banks.end()) {
        if (users.find(help[3]) == users.end()) return "FAILURE";
        if (user[help[3]].find(help[2]) == user[help[3]].end()) return "FAILURE";
        users[help[3]] += value;
        return "SUCCESS";
    }
   
    if (users.find(help[2]) == users.end() || users.find(help[3]) == users.end()) return "FAILURE";
    if (users[help[2]] < value) return "FAILURE";
    users[help[2]] -= value;
    users[help[3]] += value;
    return "SUCCESS";
}

string get(string &s) {
    vector<string> help = split(s);
    if (users.find(help[2]) == users.end()) return "FAILURE";
    return to_string(users[help[2]]);
}
static bool comp(const string &x, const string &y) {
    vector<string> a = split(x);
    vector<string> b = split(y);
    return stoll(a[1]) < stoll(b[1]);
}

string get_command_results(vector<string> commands) {
    vector<string> check;
        for (auto &it : commands) {
        if (it[0] == 'I') {
            init(it);
        } else {
            check.push_back(it);
        }
    }
   
    sort(check.begin(), check.end(), comp);
    map<string, string> res;
        for (auto &it : check) {
        if (it[0] == 'P') {
            res[it] = post(it);
        }
        if (it[0] == 'G') {
            res[it] = get(it);
        }
    }
   
    string ans;
    for (auto &it : commands) {
        if (res.find(it) != res.end()) {
            if (!ans.empty()) ans += ",";
            ans += res[it];
        }
    }
   
    return ans; 
}


Account Balance manager : StripePay Backend โœ…

Stripe โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <string>
using namespace std;
bool s(const string& s1, const string& s2) {
    if (s1.size() != s2.size()) return false;
    int diffCount = 0;
    for (int i = 0; i < s1.size(); ++i) {
    if (s1[i] != s2[i]) {
        diffCount++;
        }
    if (diffCount > 1) return false;
    }
    return (diffCount == 1);
}
vector<string> solve(const vector<string>& start, const vector<string>& fin) {
    vector<string> result(fin.size(), "NO");
    for (int i = 0; i < fin.size(); ++i) {
    for (const string& startStr : start) {
    if (s(startStr, fin[i])) {
    result[i] = "YES";
    break;
            }
        }
    }

    return result;
}
int main() {
    int n, m;
    cin >> n;
    vector<string> start(n);
    for (int i = 0; i < n; ++i) {
        cin >> start[i];
    }
    cin >> m;
    vector<string> fin(m);
    for (int i = 0; i < m; ++i) {
        cin >> fin[i];
    }
    vector<string> result = solve(start, fin);
    for (const string& res : result) {
        cout << res << endl;
    }
    return 0;
}


String operation โœ…
#include <iostream>
#define ll long long
#include <vector>
using namespace std;
ll minSelectionsInWorstCase(vector<int>& choices) {
    ll n = choices.size();
    vector<int> s(n, 0);
    ll t = 0; 
    s[n - 1] = choices[n - 1];
    for (int i = n - 2; i >= 0; --i) {
        s[i] = choices[i] + s[i + 1];
    }
   
    t = s[0];
    return t;
}


Backbencher and bug โœ…
๐Ÿ‘1