๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.52K subscribers
5.56K photos
3 videos
95 files
9.65K 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
class UserMainCode:
    @staticmethod
    def indexSort(input1, input2):
        uniq = set()
        for i in range(input1):
            if input2[i] != i + 1:
                uniq.add(input2[i])
        return input1 - len(uniq)

Index Sortโœ…
long getMaxCost(string s) {
    if (s.find('1') == string::npos) {
        return 0;
    }
    int ind = s.find('1');
    int count = 1;
    int n = s.length();
     long res = 0;
    int prev = ind;
   
    for (int i = ind + 1; i < n; ++i) {
        if (s[i] == '1') {
            if (prev != i - 1) {
                res += (i - prev) * count;
            }
            count += 1;
            prev = i;
        }
    }
   
    if (prev == n - 1) {
        prev = n;
    }
   
    return res + count * (n - prev);
}

Binary Circuit โœ…
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

long findInterestingPairs(vector<int>& arr, int sumVal) {
    sort(arr.begin(), arr.end());
    int val = sumVal / 2;
    long cc = 0;
    int ind = -1;
   
    for (int i = 0; i < arr.size(); ++i) {
        if (arr[i] == val) {
            cc++;
            if (ind == -1) {
                ind = i;
            }
        }
    }
   
    if (ind == -1) {
        return 0;
    }
   
    return ind * cc + ((cc - 1) * cc) / 2;
}.

De shaw 
Intersecting Pairsโœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include<bits/stdc++.h>
using namespace std;

const int MOD = 1e9 + 7;
vector<vector<vector<string>>> dp;

vector<string> solve(string& alice, string& bob, int i, int j) {
    if(i == alice.size() || j == bob.size()) {
        return {""};
    }
    if(dp[i][j].size() != 0) {
        return dp[i][j];
    }
    if(alice[i] == bob[j]) {
        vector<string> tmp = solve(alice, bob, i+1, j+1);
        for(string& s : tmp) {
            s = alice[i] + s;
        }
        return dp[i][j] = tmp;
    }
    vector<string> left = solve(alice, bob, i+1, j);
    vector<string> right = solve(alice, bob, i, j+1);
    if(left[0].size() > right[0].size()) {
        return dp[i][j] = left;
    }
    if(left[0].size() < right[0].size()) {
        return dp[i][j] = right;
    }
    left.insert(left.end(), right.begin(), right.end());
    sort(left.begin(), left.end());
    left.erase(unique(left.begin(), left.end()), left.end());
    return dp[i][j] = left;
}

int main() {
    int T;
    cin >> T;
    while(T--) {
        string alice, bob;
        cin >> alice >> bob;
        dp = vector<vector<vector<string>>>(alice.size(), vector<vector<string>>(bob.size()));
        vector<string> trips = solve(alice, bob, 0, 0);
        for(string& trip : trips) {
            cout << trip << endl;
        }
    }
    return 0;
}

INFAthon 4.0โœ…
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    int maxSumOptimalArrangement(vector<int>& coins) {
        vector<int> positive;
        vector<int> negative;

        for (int coin : coins) {
            if (coin >= 0)
                positive.push_back(coin);
            else
                negative.push_back(coin);
        }

        sort(positive.rbegin(), positive.rend());
       
        sort(negative.begin(), negative.end());

        int totalSum = 0;

        for (size_t i = 0; i < max(positive.size(), negative.size()); ++i) {
            if (i < positive.size())
                totalSum += positive[i];
            if (i < negative.size())
                totalSum -= negative[i];
        }

        return totalSum;
    }
};

ZS campus beat code question :

Circuit Board โœ…
int solve(vector<int>& xp) {
    sort(xp.begin(), xp.end());
    set<double> s;
    int i = 0, j = xp.size() - 1;

    while (i < j) {
        double a = (xp[i] + xp[j]) / 2.0;
        s.insert(a);
        i++;
        j--;
    }

    return s.size();
}

Amazon โœ