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

using namespace std;
long long anser(vector<int>& arr, int i, vector<long long>& dp) {
      if (i >= arr.size()) {
        return -1;
    }
    if (dp[i] != -1) {
        return dp[i];
    }
    int ans=anser(arr,i+1,dp);
    return max(ans,max(ans|arr[i],arr[i]));
}
long long answer(vector<int>& arr) {
    int n = arr.size();
    vector<long long> dp(n, -1);
    return anser(arr, 0, dp);
}


OR BITโœ…
#include <iostream>
#include <vector>
using namespace std;
pair<int, int> urgent(const vector<int>& arr, int n) {
    vector<int> freq(n + 1, 0);
    int duplicate = -1, missing = -1;
    for (int i = 0; i < n; i++) {
        freq[arr[i]]++;
    }
    for (int i = 1; i <= n; i++) {
        if (freq[i] == 0) {
            missing = i;
        } else if (freq[i] > 1) {
            duplicate = i;
        }
    }
    if (duplicate != -1 && missing != -1) {
        return {duplicate, missing};
    } else {
        return {-1, -1};
    }
}


Messed Up Array โœ…
#include <iostream>
#include <vector>
using namespace std;

void solve(int N, const vector<int>& L, const vector<int>& R) {
    vector<pair<int, int>> available_slots;
        if (L[0] > 0) {
        available_slots.push_back({0, L[0]});
    }
        for (int i = 1; i < N; ++i) {
        if (R[i-1] < L[i]) {
            available_slots.push_back({R[i-1], L[i]});
        }
    }
        if (R[N-1] < 1000000000) {
        available_slots.push_back({R[N-1], 1000000000});
    }
   
    if (available_slots.empty()) {
        cout << "-1 -1" << endl;
    } else {
        for (const auto& slot : available_slots) {
            cout << slot.first << " " << slot.second << " ";
        }
        cout << endl;
    }
}

Available Time Frames โœ…
๐Ÿ‘1
#include <iostream>
#include <vector>
#include <functional>
#include <array>

using namespace std;

using ll = long long;
ll maxValue(ll a, ll b) {
    return (a > b) ? a : b;
}

int getMinServers(int n, vector<int> f, vector<int> t, vector<int> w, vector<int> v) {
    vector<ll> size(n), maxDistance(n);
    vector<vector<array<ll, 2>>> adjacencyList(n);

    for (ll i = 0; i < f.size(); i++) {
        f[i]--;
        t[i]--;
        adjacencyList[f[i]].push_back({t[i], w[i]});
        adjacencyList[t[i]].push_back({f[i], w[i]});
    }

    ll answer = 0;

    function<void(ll, ll)> dfs1 = [&](ll u, ll parent) {
        size[u] = 1;
        ll idx = 0;
        while (idx < adjacencyList[u].size()) {
            ll vertex = adjacencyList[u][idx][0];
            ll weight = adjacencyList[u][idx][1];
            if (vertex != parent) {
                maxDistance[vertex] = maxValue(maxDistance[u] + weight, weight);
                dfs1(vertex, u);
                size[u] += size[vertex];
            }
            idx++;
        }
    };

    function<void(ll, ll)> dfs2 = [&](ll u, ll parent) {
        if (u != 0 && maxDistance[u] > v[u]) {
            answer += size[u];
        } else {
            ll idx = 0;
            while (idx < adjacencyList[u].size()) {
                ll vertex = adjacencyList[u][idx][0];
                if (vertex != parent) {
                    dfs2(vertex, u);
                }
                idx++;
            }
        }
    };

    dfs1(0, -1);
    dfs2(0, -1);

    return answer;
}


Cisco โœ…
Minserver
๐Ÿ‘3
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

int solve(int i, vector<int>& lst, int ad, const vector<int>& machineCount, const vector<int>& finalMachineCount, int shiftingCost) {
    int n = machineCount.size();
    if (i == n) {
        int res = ad;
        for (int k = 0; k < 3; ++k) {
            res += abs(lst[k] - finalMachineCount[k]);
        }
        return res;
    }
   
    int res = INT_MAX;
    res = min(res, solve(i + 1, lst, ad, machineCount, finalMachineCount, shiftingCost));
   
    for (int j = 0; j < 3; ++j) {
        lst[j] += machineCount[i];
        if (lst[j] - machineCount[i] != 0) {
            res = min(res, solve(i + 1, lst, ad + shiftingCost, machineCount, finalMachineCount, shiftingCost));
        } else {
            res = min(res, solve(i + 1, lst, ad, machineCount, finalMachineCount, shiftingCost));
        }
        lst[j] -= machineCount[i];
    }
   
    return res;
}

int getMinimumCost(const vector<int>& machineCount, const vector<int>& finalMachineCount, int shiftingCost) {
    vector<int> lst(3, 0);
    return solve(0, lst, 0, machineCount, finalMachineCount, shiftingCost);
}

GetMinimum Costโœ…
Cisco