๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.52K subscribers
5.56K photos
3 videos
95 files
9.72K 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 <bits/stdc++.h>
using namespace std;
vector<int> getGreatestElements(vector<int>& arr, int k) {
    int n = arr.size();
    vector<int> result;
    priority_queue<int, vector<int>, greater<int>> minHeap;

    for (int i = 0; i < n; ++i) {
        minHeap.push(arr[i]);
        if (minHeap.size() > k) {
            minHeap.pop();
        }
                if (i >= k - 1) {
            result.push_back(minHeap.top());
        }
    }

    return result;
}


Gamekraft โœ…
from collections import defaultdict
def getMaxRacers(speed, k):
    ans = 0
    D = defaultdict(list)
    for i, e in enumerate(speed):
        D[e].append(i)
    for arr in D.values():
        l = 0
        for r in range(len(arr)):
            while r > l and arr[r] - arr[l] - (r - l) > k:
                l += 1
            ans = max(ans, r - l + 1)
   
    return ans


GAMESKRAFT MAXRACERS โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
long long answer(vector<int>& arr, int i, vector<long long>& dp) {
    if (i >= arr.size()) {
        return 0;
    }
    if (dp[i] != -1) {
        return dp[i];
    }
   
    long long include = arr[i] | answer(arr, i + 1, dp);
    long long exclude = answer(arr, i + 1, dp);
   
    return dp[i] = max(include, exclude);
}

long long solve(int N, vector<int>& arr) {
    vector<long long> dp(N, -1);
    return answer(arr, 0, dp);
}


OR Bit โœ…
Siemens
#include <iostream>
#include <vector>
using namespace std;
int solve(int N, vector<int> workload) {
    int tot = 0;
    int maxTot = 0;
    for (auto i : workload) {
        if (i > 6) {
            tot++;
        } else {
            tot = 0;
        }
        if (tot > maxTot) {
            maxTot = tot;
        }
    }
    return maxTot;
}


Peak output โœ…
Siemens
def solve(N, Q, Specs, Queries):
    aa = {}
    for price, ram, storage in Specs:
        if (ram, storage) in aa:
            aa[(ram, storage)] = min(aa[(ram, storage)], price)
        else:
            aa[(ram, storage)] = price
    results = []
    for ram_req, storage_req in Queries:
        if (ram_req, storage_req) in aa:
            results.append(aa[(ram_req, storage_req)])
        else:
            results.append(-1)
    return results


Who wins the game
Google โœ…
#include <bits/stdc++.h>
using namespace std;

pair<int, int> countVC(const string& w) {
    unordered_set<char> v{'a', 'e', 'i', 'o', 'u'};
    int vc = 0;
    int cc = 0;
   
    for (char c : w) {
        if (v.find(c) != v.end()) {
            vc++;
        } else {
            cc++;
        }
    }
   
    return {vc, cc};
}

bool cmp(const pair<string, int>& a, const pair<string, int>& b) {
    if (a.second == b.second) {
        return a.first < b.first;
    }
    return a.second < b.second;
}

vector<string> sortWords(const string& t) {
    vector<string> ws;
    stringstream ss(t);
    string w;
   
    while (ss >> w) {
        ws.push_back(w);
    }
   
    vector<pair<string, int>> wd;
   
    for (const string& w : ws) {
        auto [vc, cc] = countVC(w);
        int diff = abs(vc - cc);
        wd.emplace_back(w, diff);
    }
   
    sort(wd.begin(), wd.end(), cmp);
   
    vector<string> res;
    for (const auto& p : wd) {
        res.push_back(p.first);
    }
   
    return res;
}

yugaByte โœ…
def minimum_payment(N, numbers):
    sorted_nums = sorted(numbers)
    median = sorted_nums[N // 2]
    total_cost = sum(abs(num - median) for num in numbers)
   
    return total_cost


Winzo Equal Numbersโœ…
#include <bits/stdc++.h>
using namespace std;


bool isPrime(int num) {
    if (num <= 1) return false;
    if (num == 2 || num == 3) return true;
    if (num % 2 == 0 || num % 3 == 0) return false;
    for (int i = 5; i * i <= num; i += 6) {
        if (num % i == 0 || num % (i + 2) == 0) return false;
    }
    return true;
}


int calculateGrundy(int x, int y) {
    return x ^ y;
}


char solve(int N, vector<pair<int, int>>& stones) {
    int xorGrundy = 0;

    for (const auto& stone : stones) {
        int x = stone.first;
        int y = stone.second;
        xorGrundy ^= calculateGrundy(x, y);
    }

    return (xorGrundy == 0) ? 'B' : 'A';
}

int main() {
    int T;
    cin >> T;

    while (T--) {
        int N;
        cin >> N;
        vector<pair<int, int>> stones(N);

        for (int i = 0; i < N; i++) {
            int x, y;
            cin >> x >> y;
            stones[i] = {x, y};
        }

        cout << solve(N, stones) << endl;
    }

    return 0;
}

game of stones
Siemensโœ…
def findMinComplexity(complexity, days):
    n = len(complexity)
    if days > n:
        return -1
   
    dp = [[float('inf')] * (days + 1) for _ in range(n + 1)]
    dp[0][0] = 0
   
    for i in range(1, n + 1):
        for j in range(1, min(i, days) + 1):
            max_complexity = 0
            for k in range(i, j - 1, -1):
                max_complexity = max(max_complexity, complexity[k - 1])
                dp[i][j] = min(dp[i][j], dp[k - 1][j - 1] + max_complexity)
   
    return dp[n][days]

Minimum complexity level
Mathwork โœ…
#include <iostream>
#include <vector>

using namespace std;

vector<int> solution(const vector<int>& numbers) {
    vector<int> result;
    int start = 0;
    int end = numbers.size() - 1;

    while (start <= end) {
        if (start <= end) {
            result.push_back(numbers[start]);
            ++start;
        }

        if (start <= end) {
            result.push_back(numbers[end]);
            --end;
        }
    }

    return result;
}


Tradedesk โœ…
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

void bfs(const vector<vector<int>>& adj, vector<bool>& visited, int start) {
    queue<int> q;
    q.push(start);
    visited[start] = true;
   
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int v : adj[u]) {
            if (!visited[v]) {
                visited[v] = true;
                q.push(v);
            }
        }
    }
}

bool isConnected(const vector<vector<int>>& adj, int N, int C) {
    vector<bool> visited(N, false);
    bfs(adj, visited, C);
    for (bool v : visited) {
        if (!v) return false;
    }
    return true;
}

int countComponents(const vector<vector<int>>& adj, int N) {
    vector<bool> visited(N, false);
    int components = 0;
   
    for (int i = 0; i < N; ++i) {
        if (!visited[i]) {
            bfs(adj, visited, i);
            ++components;
        }
    }
   
    return components;
}

int main() {
    int T;
    cin >> T;
   
    while (T--) {
        int N, M;
        cin >> N >> M;
       
        vector<vector<int>> adj(N);
       
        for (int i = 0; i < M; ++i) {
            int A, B;
            cin >> A >> B;
            adj[A].push_back(B);
            adj[B].push_back(A);
        }
       
        int C;
        cin >> C;
       
        if (isConnected(adj, N, C)) {
            cout << "Yes" << endl;
        } else {
            int components = countComponents(adj, N);
            cout << "No" << endl;
            cout << components - 1 << endl;
        }
    }
   
    return 0;
}


bob and the tour โœ