๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.52K subscribers
5.55K photos
3 videos
95 files
9.64K 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
am looking for Data Science Interns with Work From Home opportunity at Meritshot. Anybody who wants to grab this opportunity to work as a Data Science Intern can apply by sharing their resume at career@meritshot.com

You can apply even if you have zero experience in Data Science. You just need to have a willingness to learn and explore Data Science and Machine Learning.
#include<bits/stdc++.h>
using namespace std;

int main() {
    int N, K;
    cin >> N ;

    vector<int> d(N);
    for (int i = 0; i < N; ++i) {
        cin >> d[i];
    }
   
    cin >> K;
   
    int t = 0, r = 0;
    for (int i = 0; i < N; ++i) {
        if (d[i] == 1) {
            ++t;
        } else {
            ++r;
        }
    }

    if (r == 0) {
        cout << "0\n";
        return 0;
    }

    if (r < K) {
        cout << "-1\n";
        return 0;
    }

    int it = 0;
    while (r > 0) {
        r -= K;
        ++it;
    }

    cout << it << "\n";
    return 0;
}

//telecom company gwc
int solve(vector<int>& arr, int n) {
    int max_range = 0;
    int min_val, max_val;

    for (int i = 0; i < n && n - i > max_range; i++) {
        min_val = max_val = arr[i];

        for (int j = i; j < n; j++) {
            min_val = min(min_val, arr[j]);
            max_val = max(max_val, arr[j]);

            if (2 * min_val <= max_val) {
                break;
            }

            max_range = max(max_range, j - i + 1);
        }
    }

    return n - max_range;
}. 
//chat application flipkart
#include <bits/stdc++.h>
using namespace std;

struct Node {
    int v;
    int s;
    int i;
   
    Node(int val, int shelf, int index) : v(val), s(shelf), i(index) {}
};

struct Comp {
    bool operator()(const Node& n1, const Node& n2) {
        return n1.v > n2.v;
    }
};

pair<int, int> solve(const vector<vector<int>>& shelves) {
    int M = shelves.size();
    priority_queue<Node, vector<Node>, Comp> pq;
   
    int maxV = INT_MIN;
   
 
    for (int j = 0; j < M; ++j) {
        pq.push(Node(shelves[j][0], j, 0));
        maxV = max(maxV, shelves[j][0]);
    }
   
    int start = -1, end = -1;
    int minR = INT_MAX;
   
    while (true) {
        Node curr = pq.top();
        pq.pop();
       
        int mini = curr.v;
        int maxi = maxV;
       
        if (maxi - mini < minR) {
            minR = maxi- mini;
            start = mini;
            end = maxi;
        }
       
        int nextIdx = curr.i + 1;
        if (nextIdx >= shelves[curr.s].size()) {
            break;
        }
       
        int nextVal = shelves[curr.s][nextIdx];
        pq.push(Node(nextVal, curr.s, nextIdx));
        maxV = max(maxV, nextVal);
    }
   
    return {start, end};
}

int main() {
    int M, N;
   
    cin >> M>> N;
   
    vector<vector<int>> shelves(M, vector<int>(N));
   
    for (int i = 0; i < M; ++i) {
        for (int j = 0; j < N; ++j) {
            cin >> shelves[i][j];
        }
    }
   
    pair<int, int> ans = solve(shelves);
    cout << ans.first << " " << ans.second << endl;
   
    return 0;
}
//ecommerce-company
#include<bits/stdc++.h>
using namespace std;

vector<int> ans;

void dfs(vector<vector<int>>& arr, int u, int p, vector<int>& dp) {
    int cnt = 0;
    for (int it : arr[u]) {
        if (it != p) {
            dfs(arr, it, u, dp);
            if (dp[it] == 1) cnt++;
        }
    }
    if (cnt == 0) {
        ans.push_back(u);
        dp[u] = 0;
    }
}

int main() {
    int tes;
    cin >> tes;
    while (tes--) {
        ans.clear();
        int n, i, min = INT_MAX, idx = -1;
        cin >> n;
        vector<int> dp(n + 1, 1);
        for (i = 1; i <= n; i++) {
            int x;
            cin >> x;
            if (min > x) {
                min = x;
                idx = i;
            }
        }
        vector<vector<int>> arr(n + 1);
        for (i = 0; i < n - 1; i++) {
            int x, y;
            cin >> x >> y;
            arr[x].push_back(y);
            arr[y].push_back(x);
        }
        dfs(arr, idx, 0, dp);
        cout << ans.size() - 1 << endl;
        for (i = 0; i < ans.size() - 1; i++) cout << ans[i] << " ";
        cout << endl;
    }
    return 0;
}

Tree Removal โœ…
t = int(input())
    for _ in range(t):
        n = int(input())
        if n == 3:
            print("1 2 3")
        elif n % 2 == 0:
            for i in range(1, n // 2 + 1):
                print(f"{i} {n + 1 - i}", end=" ")
            print()
        else:
            for i in range(1, n // 2 + 1):
                print(f"{i} {n - i}", end=" ")
            print(n)


Split permutation โœ…
import sys
    input = sys.stdin.read
    data = input().split()
   
    index = 0
    t = int(data[index])
    index += 1
   
    results = []
   
    for _ in range(t):
        n = int(data[index])
        m = int(data[index + 1])
        index += 2
       
        a = list(map(int, data[index:index + n]))
        index += n
        b = list(map(int, data[index:index + n]))
        index += n
       
        cnt = {}
        for x in a:
            rem = x % m
            if rem in cnt:
                cnt[rem] += 1
            else:
                cnt[rem] = 1
       
        tot = 0
        for x in b:
            rem = (m - (x % m)) % m
            if rem in cnt:
                tot += cnt[rem]
       
        results.append(tot)
   
    for result in results:
        print(result)

if __name__ == "__main__":
    main()


Trick or treat โœ