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

long long solve(int N, std::vector<int> from, std::vector<int> to, std::vector<int> weight, int k) {
    std::vector<std::vector<std::pair<int, int>>> adj(N);
    for (int i = 0; i < N - 1; ++i) { // build adj
        adj[from[i]].emplace_back(to[i], weight[i]);
        adj[to[i]].emplace_back(from[i], weight[i]);
    }

    std::function<std::array<long long, 2>(int, int)> dfs = [&](int cur, int parent) {
        std::array<long long, 2> ans{};
        std::vector<long long> take, skip, diff;
        for (auto& [next, w] : adj[cur]) if (parent != next) {
            auto [not_full, full] = dfs(next, cur);
            take.push_back(not_full + w);
            skip.push_back(full);
            diff.push_back(take.back() - skip.back());
        }

        int n = int(diff.size());
        std::ranges::nth_element(diff, diff.begin() + k - 1, std::greater<>());
        ans[0] = std::reduce(diff.begin(), diff.begin() + std::min(k, n)) + std::reduce(skip.begin(), skip.end());
       
        if (n && n >= k) {
            ans[1] = ans[0];
            ans[0] -= *std::min_element(diff.begin(), diff.begin() + k);
        }

        return ans;
    };

    auto ans = dfs(0, -1);
    return std::max(ans[0], ans[1]);
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
   
    int l = 0, r = n - 1;
    while (l < n && a[l] == 0) l++;
    while (r > l && a[r] == 0) r--;

    int ans = 0;
    if ((r - l + 1) % 2 == 0) {
        if (a[l] > a[r]) {
            ans += a[r];
            r--;
        } else {
            ans += a[l];
            l++;
        }
    }

    int sum = 0, c = 1, max1 = 0, sum1 = 0, max2 = 0, sum2 = 0;
    for (int i = l; i <= r; i++) {
        sum += a[i];
        int tmp = c / 2;
        int god = (tmp * (tmp + 1)) + (tmp + 1);
        if (god <= sum && c % 2 == 1) {
            max1 = c;
            sum1 = sum;
        }
        c++;
    }

    c = 1;
    sum = 0;
    for (int i = r; i >= l; i--) {
        sum += a[i];
        int tmp = c / 2;
        int god = (tmp * (tmp + 1)) + (tmp + 1);
        if (god <= sum && c % 2 == 1) {
            max2 = c;
            sum2 = sum;
        }
        c++;
    }

    int max1h = max1 / 2, max2h = max2 / 2;
    int ans1 = (max1h * (max1h + 1)) + (max1h + 1);
    int ans2 = (max2h * (max2h + 1)) + (max2h + 1);
    cout << min(sum - sum1 + sum1 - ans1, sum - sum2 + sum2 - ans2) + ans << endl;

    return 0;
}


//bitonic array โœ…
Onix is hiring for Software Engineers

2024 batch eligibile
Delhi/Hyderabad/Pune/Bangalore
2 sept 2024 is the joining date

Selection Process :
Online Aptitude cum Technical Assessment โ€“ 95 minutes
Two Levels of Technical Interviews
HR Interview

Apply Form : https://forms.gle/sanQ1wiQKkZCN1Ss9
Role: Software development Intern
Company: Thriving Springs
Tech stacks, HTML, CSS
Good to know: Angular, Node.js
Location: Hyderabad
Mode of Work: Work from Office
Working Days: Monday to Friday; (Monday to Thursday - WFO, Friday - WFH)
Stipend - 20K/M
Duration - 6 months
Open Positions - 10
Post Completion of the Internship period, PPO offered from 5 LPA to 7.5 LPA based upon performance evaluation.

Apply here - https://forms.gle/ea47rjtc5ZUjQdrU6
๐Ÿ‘1
typedef long long ll;

pair<ll, ll> largestPowerof2(ll n)
{
ll ans = 0;
for (ll i = 30; i >= 0; i--) {
  if ((1LL << i) & n) {
   ans = i;
   break;
  }
}

ans = min(25LL, ans);
return { ans, 1LL << ans };
}

string solve(ll n)
{
string str = "abcdefghijklmnopqrstuvwxyz";
string ans = "";
while (n) {
  pair<ll, ll> a = largestPowerof2(n);
  ll pw = a.first;
  ll value = a.second;
  ans += str[pw];
  n -= value;
}
return ans;
}


ms task 2 โœ…
Company โ€“ Manmachine Car Care Pvt. Ltd.
Role โ€“ Data Analyst
Exp. โ€“ Fresher
Apply Here โ€“ https://www.linkedin.com/jobs/view/3974179593

Company โ€“ Agoda
Role โ€“ Business Data Analyst
Exp. โ€“ Fresher
Apply Here โ€“ https://www.linkedin.com/jobs/view/3822845330

Company โ€“ Deutsche Bank
Role โ€“ Data Analyst (ASC), Associate
Exp. โ€“ 0-2 yrs
Apply Here โ€“ https://www.foundit.in/job/data-analyst-asc-associate-deutsche-bank-pune-india-31092016?searchId=c021504c-29f5-4075-9a52-03284b952892

Company โ€“ Genpact
Role โ€“ Associate, Data Analyst
Exp. โ€“ 0-2 yrs
Apply Here โ€“ https://www.foundit.in/job/associate-data-analyst-genpact-bengaluru-bangalore-31103435?searchId=c021504c-29f5-4075-9a52-03284b952892

Company โ€“ Thirumoolar Software
Role โ€“ Machine Learning Engineer
Exp. โ€“ Fresher
Apply Here โ€“ https://www.linkedin.com/jobs/view/3971796148

Company โ€“ Walmart
Role โ€“ Data Scientist III
Exp. โ€“ 0-2 yrs
Apply Here โ€“ https://www.foundit.in/job/data-scientist-iii-walmart-bengaluru-bangalore-india-31110692?searchId=2e1e6619-e60d-4cfd-9341-e0447e6683cc

Company โ€“ Medtronic LABS
Role โ€“ Data Scientist
Exp. โ€“ 0-2 yrs
Apply Here โ€“ https://www.foundit.in/job/data-scientist-medtronic-labs-bengaluru-bangalore-india-31102745?searchId=aed030a2-b8e3-48b1-8844-51dc56871b66

Company โ€“ Wolters Kluwer
Role โ€“ Data Scientist
Exp. โ€“ 0-2 yrs
Apply Here โ€“ https://www.foundit.in/job/data-scientist-wolters-kluwer-pune-india-31183197?searchId=bab7c0ad-85ed-44c7-be8b-8ad18d6330f7

Company โ€“ The Sleep Company
Role โ€“ Data Analytics Intern
Exp. โ€“ Fresher
Apply Here โ€“ https://www.linkedin.com/jobs/view/3975795269
๐Ÿ‘1
#include <bits/stdc++.h>
using namespace std;

struct Results {
    string sn;
    vector<string> c;
};

int rv(const string &cd) {
    unordered_map<string, int> ro = {
        {"2", 2}, {"3", 3}, {"4", 4}, {"5", 5}, {"6", 6}, {"7", 7},
        {"8", 8}, {"9", 9}, {"10", 10}, {"J", 11}, {"Q", 12}, {"K", 13}, {"A", 14}
    };
    string r = cd.substr(0, cd.size() - 1);
    return ro[r];
}

pair<unordered_map<string, vector<string>>, unordered_map<char, vector<string>>>
pc(const vector<string> &cs) {
    unordered_map<string, vector<string>> rd;
    unordered_map<char, vector<string>> sd = {{'S', {}}, {'H', {}}, {'D', {}}, {'C', {}}};
    for (const auto &cd : cs) {
        string r = cd.substr(0, cd.size() - 1);
        char s = cd.back();
        rd[r].push_back(cd);
        sd[s].push_back(cd);
    }
    return {rd, sd};
}

Results f_sc(const vector<string> &cs) {
    auto it = max_element(cs.begin(), cs.end(), [](const string &a, const string &b) {
        return rv(a) < rv(b);
    });
    return {"single card", {*it}};
}

Results f_p(const unordered_map<string, vector<string>> &rd) {
    vector<vector<string>> ps;
    for (const auto &e : rd) {
        if (e.second.size() >= 2) {
            ps.push_back(e.second);
        }
    }
    if (!ps.empty()) {
        auto it = max_element(ps.begin(), ps.end(), [](const vector<string> &a, const vector<string> &b) {
            return rv(a[0]) < rv(b[0]);
        });
        return {"pair", {(*it)[0], (*it)[1]}};
    }
    return {"", {}};
}

Results f_t(const unordered_map<string, vector<string>> &rd) {
    vector<vector<string>> ts;
    for (const auto &e : rd) {
        if (e.second.size() >= 3) {
            ts.push_back(e.second);
        }
    }
    if (!ts.empty()) {
        auto it = max_element(ts.begin(), ts.end(), [](const vector<string> &a, const vector<string> &b) {
            return rv(a[0]) < rv(b[0]);
        });
        return {"triple", {(*it)[0], (*it)[1], (*it)[2]}};
    }
    return {"", {}};
}

Results f_fr(const vector<string> &cs) {
    vector<string> sc = cs;
    sort(sc.begin(), sc.end(), [](const string &a, const string &b) {
        return rv(a) < rv(b);
    });

    unordered_map<int, string> vtcd;
    for (const auto &cd : sc) {
        vtcd[rv(cd)] = cd;
    }

    for (int i = 14; i >= 5; --i) {
        if (vtcd.count(i) && vtcd.count(i - 1) && vtcd.count(i - 2) &&
            vtcd.count(i - 3) && vtcd.count(i - 4)) {
            return {"five in a row", {vtcd[i], vtcd[i - 1], vtcd[i - 2],
                                      vtcd[i - 3], vtcd[i - 4]}};
        }
    }
    return {"", {}};
}

Results f_s(const unordered_map<char, vector<string>> &sd) {
    vector<char> so = {'S', 'H', 'D', 'C'};
    for (char s : so) {
        if (sd.at(s).size() >= 5) {
            return {"suit", vector<string>(sd.at(s).begin(), sd.at(s).begin() + 5)};
        }
    }
    return {"", {}};
}

Results f_tp(const unordered_map<string, vector<string>> &rd) {
    vector<vector<string>> ts;
    vector<vector<string>> ps;
    for (const auto &e : rd) {
        if (e.second.size() >= 3) {
            ts.push_back(e.second);
        } else if (e.second.size() >= 2) {
            ps.push_back(e.second);
        }
    }
    if (!ts.empty() && !ps.empty()) {
        auto ht = max_element(ts.begin(), ts.end(), [](const vector<string> &a, const vector<string> &b) {
            return rv(a[0]) < rv(b[0]);
        });
        auto hp = max_element(ps.begin(), ps.end(), [](const vector<string> &a, const vector<string> &b) {
            return rv(a[0]) < rv(b[0]);
        });
        return {"a triple and a pair", {(*ht)[0], (*ht)[1], (*ht)[2], (*hp)[0], (*hp)[1]}};
    }
    return {"", {}};
}