๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.52K subscribers
5.56K photos
3 videos
95 files
9.68K 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
int findLowestPrice(vector<vector<string>> products, vector<vector<string>> discounts) {
    int cost = 0;
    map<string, int> mp;
    for (vector<string> &d : discounts) {
        string id = d[0];
        int gg = d[1][0] - '0';
        int disc = stoi(d[2]);
        if (gg == 0) {
            if (mp[id].find(0) == mp[id].end()) {
                mp[id][0] = disc;
            }
        }
        else {
            mp[id][0] = min(mp[id][0], disc);
        }
        else mp[id][gg]=max(mp[id][gg],disc);
    }
    for (vector<string> &p : products) {
        int price = stoi(p[0]), no_gravity12 = price;
        for (int i = 1; i < m; i++) {
            if (p[i] != "EMPTY") {
                string id = p[i];
                int d1 = mp[id][1];
                int d2 = mp[id][2];
                int price0 = mp[id].find(0) != mp[id].end() ? mp[id][0] : 0;
                int price1 = max(0, price - (d1 * price + 99)/100);
                int price2 = max(0, price - d2);
                gg = min(gg, price0, price1, price2);
            }
        }
        cost += gg;
    }
    return cost;
}

Shopping Cart Billing โœ…
vector<string> processLogs(vector<string> logs, int threshold) {
  unordered_map<string, int> transaction_cou
nt;

    for (const string& log : logs
) {
        istringstream iss(lo
g);
        string sender, recipie
nt;
        int amou
nt;
        iss >> sender >> recipient >> amou
nt;

    
 
        transaction_count[sender]
++;
    
 
        if (sender != recipient
) {
            transaction_count[recipient]
++;
     
}
 
  }

    vector<string> suspicious_use
rs;
    for (const auto& entry : transaction_count
) {
        if (entry.second >= threshold
) {
            suspicious_users.push_back(entry.firs
t);
     
}
 
  }


  sort(suspicious_users.begin(), suspicious_users.end(
));

    return suspicious_use
rs;
}

Suspicious activity from logs โœ…
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int findMinWeight(vector<int> weights, int d) {

    priority_queue<int> maxHeap(weights.begin(), weights.end());

    for (int i = 0; i < d; ++i) {
        int maxWeight = maxHeap.top();
        maxHeap.pop();
        int remainingWeight = maxWeight / 2;
      maxHeap.push(maxWeight - remainingWeight);
    }

    int totalWeight = 0;
    while (!maxHeap.empty()) {
        totalWeight += maxHeap.top();
        maxHeap.pop();
    }
   
    return totalWeight;
}

Minimum total weight โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Solution {
public:
    int maximumInvitations(vector<int>& favourite) {
        int n = favourite.size();
        vector<bool> duoNode(n, false);
        vector<int> indegree(n, 0);
        vector<int> maxPathAt(n, 1);
       
        for (int i = 0; i < n; i++) {
            indegree[favourite[i]]++;
            if (favourite[favourite[i]] == i) {
                duoNode[i] = true;
                duoNode[favourite[i]] = true;
            }
        }
       
        int ans = 0;
        vector<bool> visited(n, false);
       
        for (int i = 0; i < n; i++) {
            if (!indegree[i]) {
                int cur = i;
                while (!duoNode[cur] && !visited[cur] && !indegree[cur]) {
                    visited[cur] = true;
                    maxPathAt[favourite[cur]] = max(maxPathAt[favourite[cur]], maxPathAt[cur] + 1);
                    cur = favourite[cur];
                    indegree[cur]--;
                }
            }
        }
       
        for (int i = 0; i < n; i++) {
            if (duoNode[i]) {
                ans += maxPathAt[i];
            }
        }
       
        int offset = 1;
        fill(maxPathAt.begin(), maxPathAt.end(), 0);
        fill(visited.begin(), visited.end(), false);
       
        for (int i = 0; i < n; i++) {
            if (!visited[i]) {
                int prev, cur = i;
                while (!maxPathAt[cur]) {
                    maxPathAt[cur] = offset++;
                    prev = cur;
                    cur = favourite[cur];
                }
                if (!visited[cur]) {
                    ans = max(ans, maxPathAt[prev] - maxPathAt[cur] + 1);
                }
                cur = i;
                while (!visited[cur]) {
                    visited[cur] = true;
                    cur = favourite[cur];
                }
            }
        }

        return ans;
    }
};

int main() {
    Solution solution;
    int N;
    cin >> N;
    vector<int> favourite(N);
   
    for (int i = 0; i < N; i++) {
        cin >> favourite[i];
        favourite[i]--;
    }

    int result = solution.maximumInvitations(favourite);
    cout << result << endl;

    return 0;
}

Barclays โœ…
#include <iostream>

using namespace std;

void cellCompete( int *arr, int days )
{
    int num = 0;
    for( int i = 0; i < 8; i++ )
    {
        num = ( num << 1 ) | arr[i];
    }

    for( int i = 0; i < days; i++ )
    {
        num = num << 1;
        num = ( ( ( num << 1 ) ^ ( num >> 1 ) ) >> 1 ) & 0xFF;
    }

    for( int i = 0; i < 8; i++ )
    {
        arr[i] = ( num >> 7 - i ) & 0x01;
    }
}

Pespico โœ…
import heapq
def minStops(a, b, c, d, e):
    f = sorted(zip(b, c))
    g = []
    heapq.heapify(g)
    h = e 
    i = 0 
    j = 0
    for k in range(a):
        l, m = f[k]
        n = l - j
        while h < n:
            if not g:
                return -1
            h += -heapq.heappop(g)
            i += 1
        h -= n
        j = l
        heapq.heappush(g, -m)
    o = d - j
    while h < o:
        if not g:
            return -1
        h += -heapq.heappop(g)
        i += 1
    return i
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <bits/stdc++.h>
using namespace std;
struct T {
    string n;
    int p, e;
    T(string n, int p, int e) : n(n), p(p), e(e) {}
};

struct C {
    bool operator()(const T &a, const T &b) {
        if (a.p == b.p) return false;
        return a.p < b.p;
    }
};

vector<string> CircularPriorityDequeue(vector<string> a, vector<int> b, vector<int> c, vector<int> d) {
    map<int, deque<T>, greater<int>> m;
    vector<string> r;
    for (int i = 0; i < a.size(); ++i) m[b[i]].emplace_back(a[i], b[i], c[i]);

    for (int q : d) {
        if (q == 1) {
            if (m.empty()) {
                r.push_back("Dequeued: EMPTY");
                continue;
            }
            auto &h = m.begin()->second;
            r.push_back("Dequeued: " + h.front().n);
            h.pop_front();
            if (h.empty()) m.erase(m.begin()->first);
        } else if (q == 2) {
            if (m.empty()) {
                r.push_back("Executed: EMPTY");
                continue;
            }
            auto &h = m.begin()->second;
            r.push_back("Executed: " + h.front().n);
            h.pop_front();
            if (h.empty()) m.erase(m.begin()->first);
        } else if (q == 3) {
            int s = 0;
            for (const auto &e : m) s += e.second.size();
            r.push_back("Size: " + to_string(s));
        }
    }
    return r;
}


Task Scheduling Optimization โœ…
Cars24
vector<vector<int>> adj;
vector<int> vis;
void solve() {
  int n;
  cin >> n;
  adj.resize(n);
  for(int i = 0 ; i < n ; i++){
    int x;cin >> x;
    int N = i + x;
    int P = i - x;
    if(N < n)
      adj[N].push_back(i);
    if(P >= 0)
      adj[P].push_back(i);
  }
  vis.resize(n, -1);
  queue<int> Q;
  Q.push(n-1);
  vis[n-1] = 0;
  while(!Q.empty()){
    int u = Q.front();
    Q.pop();
    for(int v : adj[u]){
      if(vis[v] == -1){
        Q.push(v);
        vis[v] = 1 + vis[u];
      }
    }
  }
  for(int i = 0; i < n ; i++)
    cout << vis[i] <<endl;
}


Servers Time โœ…
Razorpay
long long solve(int N,int M,vector<int>Arr){
    vector<int>v(N+1,INT_MAX);
    int n=N;
    for(int i=n-1;i>=0;i--){
        v[i]=min(v[i+1],Arr[i]);
    }
    long long ans=INT_MAX;
    for(int i=0;i<N;i++){
        if((i+M-1)<N){
            ans=min(ans,1ll*Arr[i]*v[i+M-1]);
        }
    }
    return ans;


Array transferโœ…
class Solution{
public:
    bool solvable(vector<int>& v,int diff,int K){
    
        int n=v.size();
        int prev=0;
        int removed=0;
        for(int i=1;i<n&&removed<K;i++){
            if(i==n-1 || v[i+1]-v[prev]>diff){
                if(v[i]-v[prev]>diff)return false;
                prev=i;
            }
            else removed++;
        }
        return (removed==K);
    }
   
    int minDiff(vector<int> v,int K){
       
        int hi=v.back()-v[0];
        int lo=0;
       
        for(int i=0;i+1<v.size();i++)lo=max(lo,v[i+1]-v[i]);
       
        while(lo<hi){
            int mid=(lo+hi)/2;
            if(solvable(v,mid,K))hi=mid;
            else lo=mid+1;
        }
        return lo;       
    }
};

Adjacent cubes โœ