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

using namespace std;

const int MAXN = 1e5 + 5;

class SegmentTree {
private:
    vector<int> tree, lazy;
    int n;

    void build(int node, int start, int end) {
        if (start == end) {
            tree[node] = 0;
            return;
        }
        int mid = (start + end) / 2;
        build(2 * node, start, mid);
        build(2 * node + 1, mid + 1, end);
        tree[node] = max(tree[2 * node], tree[2 * node + 1]);
    }

    void push(int node, int start, int end) {
        if (lazy[node] != 0) {
            tree[node] += lazy[node];
            if (start != end) {
                lazy[2 * node] += lazy[node];
                lazy[2 * node + 1] += lazy[node];
            }
            lazy[node] = 0;
        }
    }

    void update(int node, int start, int end, int l, int r, int val) {
        push(node, start, end);
        if (start > r || end < l) return;
        if (l <= start && end <= r) {
            lazy[node] += val;
            push(node, start, end);
            return;
        }
        int mid = (start + end) / 2;
        update(2 * node, start, mid, l, r, val);
        update(2 * node + 1, mid + 1, end, l, r, val);
        tree[node] = max(tree[2 * node], tree[2 * node + 1]);
    }

    pair<int, int> query(int node, int start, int end, int l, int r) {
        push(node, start, end);
        if (start > r || end < l) return {-1, -1};
        if (l <= start && end <= r) return {tree[node], start};
        int mid = (start + end) / 2;
        pair<int, int> left = query(2 * node, start, mid, l, r);
        pair<int, int> right = query(2 * node + 1, mid + 1, end, l, r);
        if (left.first >= right.first) return left;
        return right;
    }

public:
    SegmentTree(int size) : n(size) {
        tree.resize(4 * n);
        lazy.resize(4 * n);
        build(1, 0, n - 1);
    }

    void update(int l, int r, int val) {
        update(1, 0, n - 1, l, r, val);
    }

    pair<int, int> query(int l, int r) {
        return query(1, 0, n - 1, l, r);
    }
};

void solve(int N, int Q, vector<vector<int>>& queries) {
    SegmentTree st(N + 1);

    for (const auto& query : queries) {
        int type = query[0];
        if (type == 1 || type == 2) {
            int L = query[1], R = query[2];
            st.update(L, R, 1);
        } else if (type == 3) {
            int C = query[1];
            pair<int, int> result = st.query(C, N);
            cout << result.second << '\n';
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
   
    int T;
    cin >> T;

    while (T--) {
        int N, Q;
        cin >> N >> Q;

        vector<vector<int>> queries(Q);
        for (int i = 0; i < Q; ++i) {
            int type;
            cin >> type;
            if (type == 1 ) {
                int L=1, R;
                cin >> R;
                queries[i] = {type, L, R};
            }
            else if (type == 2) {
                int L, R=N;
                cin >> L ;
                queries[i] = {type, L, R};
            }
             else {
                int C;
                cin >> C;
                queries[i] = {type, C};
            }
        }

        solve(N, Q, queries);
    }

    return 0;
}

Maximum Product Sales โœ…
๐Ÿ‘2
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
public class Solution {
    public static int countOfElement(int[] listInput1, int[] listInput2) {
        HashSet<Integer> set1 = new HashSet<>();
        HashSet<Integer> set2 = new HashSet<>();

     
        for (int num : listInput1) {
            set1.add(num);
        }

       
        for (int num : listInput2) {
            set2.add(num);
        }

      
        int count = 0;
        for (int num : listInput1) {
            if (!set2.contains(num)) {
                count++;
            }
        }
        for (int num : listInput2) {
            if (!set1.contains(num)) {
                count++;
            }
        }

        return count;
    }
}
class UserMainCode(object):
    @classmethod
    def qualifyingScore(cls, total_scores, num_top_scores, scores, weights):
        weighted_scores = [score -weight for score, weight in zip(scores, weights)]
        weighted_scores.sort(reverse=True)
        top_scores_sum = sum(weighted_scores[:num_top_scores])
        if top_scores_sum >= 35:
            return f"Qualified {top_scores_sum}"
        else:
            return f"Disqualified {top_scores_sum}"


Qualifying Score โœ…
void replaceValues(int SIZE, int arr[])
{
    int i=0;
    while(i<SIZE){
        if(SIZE%2==0){
            arr[i]=0;
        }
        else{
            arr[i]=1;
        }
        i+=1;
    }
}


Morgan Stanley โœ…
๐Ÿ‘1
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int ss(int a, vector<int>& b, int c, int s) {
    sort(b.begin(), b.end());
    int count = 0;
    for (int i = 0; i < a; ++i) {
        int current_capacity = b[i];
                int low = c - current_capacity;
        int high = s - current_capacity;
       
        auto left_index = lower_bound(b.begin() + i + 1, b.end(), low);
        auto right_index = upper_bound(b.begin() + i + 1, b.end(), high);
       
        // Count valid pairs
        count += distance(left_index, right_index);
    }

    return count;
}

int main() {
    int a; 
    cin >> a;
   
    vector<int> b(a);
    for (int i = 0; i < a; ++i) {
        cin >> b[i];
    }
   
    int c, s;
    cin >> c >> s;
   
    cout << ss(a, b, c, s) << endl;

    return 0;
}


MS electic powerโœ…
Morgan Stanley
๐Ÿ‘1
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

class node {
public:
    long long ind;
    char c;
    long long t;

    node() {}

    node(long long ind, char c, long long t) {
        this->ind = ind;
        this->c = c;
        this->t = t;
    }
};

bool cmp(const node &a, const node &b) {
    return a.ind < b.ind;
}

vector<string> fun(int n, vector<pair<int, char>> messages) {
    vector<node> v(n);
    for (int i = 0; i < n; i++) {
        long long ind = messages[i].first;
        char c = messages[i].second;
        long long t = i;
        node temp(ind, c, t);
        v[i] = temp;
    }

    sort(v.begin(), v.end(), cmp);

    vector<pair<long long, string>> check;
    vector<string> ans;

    for (int i = 0; i < n; i++) {
        if (v[i].c == '*') {
            int j = i + 1;
            while (j < n && v[j].c != '*' && v[j - 1].ind + 1 == v[j].ind) j++;
            if (j < n && v[j].c == '*') {
                long long mx = 0;
                string temp = "";
                for (int k = i + 1; k < j; k++) temp.push_back(v[k].c);
                for (int k = i; k <= j; k++) mx = max(mx, v[k].t);
                check.push_back({mx, temp});
            }
        }
    }

    sort(check.begin(), check.end(), [](const pair<long long, string> &a, const pair<long long, string> &b) {
        return a.first > b.first;
    });

    for (const auto &entry : check) ans.push_back(entry.second);

    return ans;
}

int main() {
    vector<pair<int, char>> in = {{693232583, '*'}, {1, '*'}, {2, 'a'}, {693232585, '*'}, {3, '*'}, {693232584, 'w'}};
    int n = in.size();

    vector<string> result = fun(n, in);

    for (const string &str : result) {
        cout << str << endl;
    }

    return 0;
}

Message passing โœ…
Morgan Stanley
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
    int minSideJumps(vector<int>& obstacles) {
        const int inf = 1 << 30; 
        vector<int> f(3, inf);   
        f[1] = 0;              

        for (int i = 0; i < obstacles.size(); ++i) {
            vector<int> new_f(3, inf); 
            for (int j = 0; j < 3; ++j) {
                if (obstacles[i] != j + 1) {
                    new_f[j] = min(f[j], min({f[(j + 1) % 3], f[(j + 2) % 3]}) + 1);
                }
            }
                        f = new_f;
        }
        return min({f[0], f[1], f[2]});
    }
};
#include <bits/stdc++.h>
using namespace std;
long long getMinimumTotalCost(vector<int>& weights, int k) {
    vector<int> adjSums;
    int n = weights.size();
    for (int i = 0; i < n - 1; i++) {
        adjSums.push_back(weights[i] + weights[i + 1]);
    }
    sort(adjSums.begin(), adjSums.end());
    long long minCost = weights[0] + weights[n - 1];
    for (int i = 0; i < k - 1; i++) {
        minCost += adjSums[i];
    }
    return minCost;
}