๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.57K subscribers
5.59K photos
3 videos
95 files
10K 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
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
Uber โœ…
๐Ÿ‘1
void dfs(int curr, int p, vector<int>* e, vector<int>& v, vector<int>& par, vector<int>& A){
    par[curr] = p;
    v[curr] = A[curr - 1];
    for(auto it : e[curr]){
        if(it == p) continue;
        dfs(it, curr, e, v, par, A);
        v[curr] += v[it];
    }
}
int solve(int N, vector<vector<int>> edges, vector<int> A){
    vector<int> e[N+1];
    map<vector<int>, int> mp;
    int c = 0;
    for(auto it : edges){
        e[it[0]].push_back(it[1]);
        e[it[1]].push_back(it[0]);
        mp[{it[0], it[1]}] = mp[{it[1], it[0]}] = c;
        c++;
    }
    int sum = 0;
    for(auto it : A) sum += it;
    vector<int> v(N+1, 0), par(N+1, 0);
    dfs(1, 0, e, v, par, A);
    int ans = sum;
    int id = edges.size();

    for(int i = 1; i <= N; i++){
        int a = sum - v[i];
        if(abs(a - v[i]) < ans){
            ans = abs(a - v[i]);
            id = mp[{par[i], i}] + 1;
        }
        else if(abs(a - v[i]) == ans){
            id = min(id, mp[{par[i], i}] + 1);
        }
    }
    return id;
}

Division Nodes โœ…
Uber
typedef long long ll;

void solve() {

  ll n = N;
  vector<vector<ll>>arr(n, vector<ll>(3));
  for (int i = 0; i < n; i++) {
    arr[i] = {[0] = people[i] , [1] = starting[i] , [2] = ending[i]};
  }
  sort(arr.begin() , arr.end() , [&](vector<ll>& a , vector<ll>& b) {
    if (a[1] == b[1]) return a[2] < b[2];
    return a[1] < b[1];
  });

  ll sum = 0;
  for (auto& x : arr) sum += x[0];

  vector<ll>dp(n, -1);
  auto recurr = [&](ll i , auto && recurr)->ll{
    if (i >= n) return 0;

    ll& ans = dp[i];
    if (ans != -1) return ans; ans = 0;

    ans = recurr(i + 1 , recurr);
    ll low = i , high = n , val = arr[i][2];
    while (high - low > 1) {
      ll mid = (low + high) >> 1;
      if (val >=  arr[mid][1]) low = mid;
      else high = mid;
    }

    ans = max(ans, arr[i][0] + recurr( low + 1 , recurr) );

    return ans;
  };



  return sum - recurr(0, recurr);

}

Meeting Room โœ…
Uber
#include <bits/stdc++.h>
  using namespace std;

  #define int long long
 
  vector<pair<int,int>> v;
  int dp[1005][1005];
  int solve(int i,int alice,int bob){
    if(i==v.size()) return 0;
   
    if(dp[alice][bob]!=-1) return dp[alice][bob];
   
    int v1=abs(v[alice].first-v[i].first) + abs(v[alice].second-v[i].second);
    int v2=abs(v[bob].first-v[i].first) + abs(v[bob].second-v[i].second);
   
    int al=v1 + solve(i+1,i,bob);
    int bb=v2 + solve(i+1,alice,i);
   
    return dp[alice][bob]=min(al,bb);
  }
 
  signed main() {
    int n;
    cin>>n;
   
    v.resize(n+2);
   
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n+2;i++){
      cin>>v[i].first>>v[i].second;
    }
   
    cout<<solve(2,0,1);

    return 0;

  }

Falling Apples โœ…
๐Ÿ‘1
int solve(vector<int> &a){
    vector<int> xorr(128, -1);
    xorr[0] = 0;

    for(auto i: a){
        for(int v=0; v<128; v++){
            if(xorr[v]!=-1){
                if(xorr[v]<i and builtin_popcount(v)<=builtin_popcount(i)){
                    int newx = v^i;
                    if(xorr[newx]==-1) xorr[newx] = i;
                    else xorr[newx] = min(i, xorr[newx]);
                }
            }
        }
    }

    int cnt = 0;
    for(auto i: xorr){
        if(i!=-1) cnt++;
    }
    return cnt;
}

Media net xor subsequence โœ…
Walmart Converge Sparkathon

Chance to interview at Walmart for Software Engineering Internships and Full Time roles with a package of 23 LPA and a stipend of 1 Lakh/month.

Open to all engineering colleges in India who are pursuing the following degrees in circuit branches (ECE, EE, EEE, IT, CS):

BE/B.Tech - Batch of 2024 and 2025 (1st and 2nd-year students are not eligible to apply)

Dual degree full-time program - Batch of 2024 and 2025 (1st/2nd/3rd-year students are not eligible to apply)

ME/M.Tech. full-time programs - Batch of 2024 (1st-year students are not eligible to apply)

Apply Link: https://walmart.converge.tech/content/converge/en_in/sparkathon.html