๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
def maximum_learning(iv, articles, p):
    size = len(articles)
    art = [x * 2 for x in articles]
    ivs = iv

    return knap_sack_top_down(ivs, art, p, size)

def knap_sack_top_down(val, wt, W, n):
    mat = [[0] * (W + 1) for _ in range(n + 1)]

    for i in range(1, n + 1):
        for j in range(1, W + 1):
            if i == 0 or j == 0:
                mat[i][j] = 0
            elif wt[i - 1] <= j:
                mat[i][j] = max(val[i - 1] + mat[i - 1][j - wt[i - 1]], mat[i - 1][j])
            else:
                mat[i][j] = mat[i - 1][j]

    return mat[n][W]

Meesho โœ…
import heapq
def getSeatsAllocation(arr):
    n = len(arr)
    ppl = [[] for i in range(2 * n + 4)]
   
    for i, x in enumerate(arr):
        ppl[x].append(i)

    h = []
    ans = [-1] * n
   
    for pos in range(1, 2 * n + 1):
        for i in ppl[pos]:
            heapq.heappush(h, (-pos, i))
       
        if len(h) > 0:
            ans[heapq.heappop(h)[1]] = pos
   
    return ans

Meesho โœ…
def max_tie_moments(n, moments):
    max_tie_count = 0
    current_difference = 0

    for moment in moments:
        bob_goals, noddy_goals = moment
        difference = bob_goals - noddy_goals
        if difference == current_difference:
            max_tie_count += 1
        elif difference > current_difference:
            current_difference = difference
            max_tie_count = 0 

    return max_tie_count
def alternatingParityPermutations(n):
    result = []

    def backtrack(permutation, used):
        if len(permutation) == n:
            result.append(permutation.copy())
            return

        for i in range(1, n + 1):
            if not used[i]:
                if not permutation or (permutation[-1] % 2 != i % 2):
                    permutation.append(i)
                    used[i] = True
                    backtrack(permutation, used)
                    used[i] = False
                    permutation.pop()

    used_numbers = [False] * (n + 1)
    backtrack([], used_numbers)
    return result

Meesho โœ…
def binary_exponentiation(base, exponent, mod=None):
    result = 1
    base = base % mod if mod else base

    while exponent > 0:
        if exponent % 2 == 1:
            result = (result * base) % mod if mod else result * base
        base = (base * base) % mod if mod else base * base
        exponent //= 2

    return result

def calculate_expression(n):
    mod = 10**9 + 7  # You can use a different modulus if needed
    return (binary_exponentiation(26, n, mod) -
            3 * binary_exponentiation(25, n, mod) -
            n * binary_exponentiation(25, n-1, mod) +
            3 * binary_exponentiation(24, n, mod) +
            2 * n * binary_exponentiation(24, n-1, mod) -
            binary_exponentiation(23, n, mod) -
            n * binary_exponentiation(23, n-1, mod)) % mod
Exciting Opportunity for MBA Grads at EY! ๐Ÿš€

EY is looking to onboard MBA graduates with a passion for Tech-Driven Business Process Improvement! If you meet the following criteria, this could be the opportunity you've been waiting for:

Criteria:
1. MBA from a tier-1 institute (2019, 2020, 2021, and 2022 batches)
2. 2-4 years of experience in management consulting from a tier-1 firm
3. Based out of Mumbai/ Delhi/ Bangalore and willing to travel for case work
4. Strong communication and interpersonal skills

If you fit the bill, don't miss out on this chance! Send your resumes to tathagata.ghosh1@in.ey.com and take the next step in your career with EY! ๐ŸŒŸ
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll solve(ll k, ll s) {
    auto comb = [](ll n) {
        return n * (n - 1) / 2;
    };

    if (k > 3 * s) return 0;

    ll ans = comb(k + 2);

    if (k > s) ans -= 3 * comb(k - s + 1);
    if (k - 2 >= 2 * s) ans += 3 * comb(k - 2 * s);

    return ans;
}

int main() {
    ll n, s;
    cin >> n >> s;
    cout << solve(s,n) << endl;
    return 0;
}

Distribute Car Toy
Service Now โœ…
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> freq(n, vector<int> (26, 0));
    string s;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for(auto &ch : s)  
            freq[i][ch - 'a']++;
    }
    long long ans = 0;
    for(int i = 0; i < 26; i++) {
        int minValue = INT_MAX;
        for(int j = 0; j < n; j++)
            minValue = min(minValue, freq[j][i]);
        ans += minValue;
    }
    cout << ans << endl;
}

Service Now โœ…
#include<bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> nums(n);
    for(int i = 0; i < n; i++) {
        cin >> nums[i];
    }
    nums.erase(unique(nums.begin(), nums.end()), nums.end());
    int sum = 0;
    for(int i = 0; i < nums.size(); i++) {
        sum += pow(2, nums[i]);
    }
    cout << sum << endl;
    return 0;
}


Special sum โœ…
Service Now
#include<bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    multiset<int, greater<int>> s;
    for(int i = 0; i < N; i++) {
        int x;
        cin >> x;
        s.insert(x);
    }
    int count = 0;
    while(!s.empty()) {
        int x = *s.begin();
        s.erase(s.begin());
        if(s.empty() || *s.begin() != x) {
            count++;
            if(x / 2 > 0)
                s.insert(x / 2);
        } else {
            s.erase(s.lower_bound(x), s.upper_bound(x));
        }
    }
    cout << count << endl;
    return 0;
}


Counting problem โœ…
Service Now
#include<bits/stdc++.h>
using namespace std;

string solve(string s, int k) {
    string vowels = "aeiou";
    string result = "";
    for (char c : s) {
        if (vowels.find(c) != string::npos) {
            k += 2;
        } else {
            k += 1;
        }
        result += to_string(k * int(c)) + " ";
    }
    return result;
}

int main() {
    string s;
    int k;
    cin >> s >> k;
    cout << solve(s, k) << endl;
    return 0;
}


Enciphering a String โœ…
Service Now
#include<bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i=0; i<n; i++) {
        cin >> arr[i];
    }
    unordered_set<int> s;
    vector<int> res(n);
    for(int i=n-1; i>=0; i--) {
        if(s.find(arr[i]) != s.end()) {
            res[i] = 1;
        } else {
            res[i] = -1;
            s.insert(arr[i]);
        }
    }
    for(int i=0; i<n; i++) {
        cout << res[i] << " ";
    }
    cout << endl;
    return 0;
}


Elements on the right side โœ…
Service Now
#include<bits/stdc++.h>
using namespace std;

int solve(vector<int>& A) {
    int n = A.size();
    if (n <= 2) return n;
    vector<unordered_map<int, int>> dp(n);
    int res = 2;
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < i; ++j) {
            int diff = A[i] - A[j];
            dp[i][diff] = max(dp[i][diff], dp[j][diff] + 1);
            res = max(res, dp[i][diff] + 1);
        }
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i = 0; i < n; i++) {
        cin >> A[i];
    }
    cout << solve(A) << endl;
    return 0;
}


Consequtive longest ap โœ…
Service Now
#include<bits/stdc++.h>
using namespace std;

int solve(vector<int>& v) {
    int n = v.size();
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j <= min(i+3, n-1); j++) {
            dp[j] = min(dp[j], dp[i] + abs(v[i] - v[j]));
        }
    }
    return dp[n-1];
}

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }
    cout <<solve(v) << endl;
    return 0;
}


Three jump โœ…
Service Now
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Diamond Boxes โœ… Service Now
bool check(vector<int>&v,int mid,int t){
    int trip=0,curr=0;
    for(auto it : v){
        if(it>mid)return false;
        if(curr+it>mid){
            trip++;
            curr=it;
        }
        else curr+=it;
    }
    if(curr>0)trip++;
    return trip<=t;
}

void diamondBoxes(){
    int n;
    cin>>n;
    vector<int>v(n);
    int l=0,r=0;
    for(int i=0;i<n;i++){
        cin>>v[i];
        l=max(l,v[i]);
        r+=v[i];
    }
    int t;
    cin>>t;
    while(l<r){
        int mid=l+(r-l)/2;
        if(check(v,mid,t))r=mid;
        else l=mid+1;
    }
    cout<<l<<endl;
   
}

Diamond Boxes โœ…
#include<bits/stdc++.h>
using namespace std;
int main(){

     long long i,j,n,m,a,b,cnt;
     while(cin>>n)
     {
         long long f[10000],a[1000];
         memset(f,0,sizeof(f));
         for(i=0;i<n;i++)
         {
             cin>>a[i];
             f[i]=0;
         }
         sort(a,a+n);
          cnt=0;
         for(i=0;i<n;i++){
            for(j=i+1;j<n;j++){
                if(f[j]==0&&a[i]<a[j])
                {
                        cnt++;
                        f[j]=1;
                        break;
                }
            }
         }
         cout<<cnt<<endl;
     }
     return 0;
}

Art โœ…
Service Now