allcoding1
27.7K subscribers
2.2K photos
2 videos
77 files
852 links
Download Telegram
#include<bits/stdc++.h>
using namespace std;

bool solve(char c) {
    c = tolower(c);
    return !(c == 'a' c == 'e' c == 'i' c == 'o' c == 'u') && c >= 'a' && c <= 'z';
}

int main() {
    string s;
    cin >> s;
    int count = 0;
    for(int i = 0; i < s.length(); i += 2) {
        if(solve(s[i])) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Airtel Shecode
anabellle
@allcoding1
#include <iostream>

using namespace std;

int main() {
    int e, d;
    cin >> e >> d;
   
    int mE = 0;
    int mN = 0;
   
    for (int i = 1; i <= d; i++) {
        int gE = e * i;
        int gN = 0;
       
        while (gE % 10 == 0) {
            gN++;
            gE /= 10;
        }
       
        if (gN > mN) {
            mN = gN;
            mE = e * i;
        } else if (gN == mN) {
            mE = max(mE, e * i);
        }
    }
   
    cout << mE << endl;
   
    return 0;
}


goodenergy

@allcoding1
👍1
#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main() {
    ll n;
    cin >> n;
    vector<ll> v(n);
    for(ll i=0; i<n; i++)
        cin >> v[i];

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

    ll sum = 0;
    for(ll i=0; i<n; i++) {
        if(sum + v[i] < 0)
            return cout << -1, 0;
        sum += v[i];
    }

    if(sum % 2 == 0)
        cout << -1;
    else
        cout << sum;

    return 0;
}


fortunejob

@allcoding1
allcoding1
Photo
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

int getMaxMedian(vector<int> lower_bound, vector<int> upper_bound, long int max_sum) {
    int n = lower_bound.size();
    long long curr_sum = 0;
    for (int i = 0; i < n; ++i) {
        curr_sum += lower_bound[i] + upper_bound[i];
    }
    int num_elements = 2 * n;
    long long target_sum = curr_sum + max_sum;
    sort(upper_bound.begin(), upper_bound.end());
    int median_index = num_elements / 2;
    int left = 1, right = INT_MAX;
    while (left <= right) {
        int mid = left + (right - left) / 2;
        long long sum = 0;
        for (int i = 0; i < n; ++i) {
            if (upper_bound[i] <= mid) {
                sum += upper_bound[i];
            } else {
                sum += mid;
            }
        }
        if (sum <= target_sum) {
            left = mid + 1;
        } else {
            right = mid - 1;
        }
    }
    return right;
}

int main() {
    int n;
    cin >> n;
    vector<int> lower_bound(n);
    vector<int> upper_bound(n);
    for (int i = 0; i < n; ++i) {
        cin >> lower_bound[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> upper_bound[i];
    }
    long int max_sum;
    cin >> max_sum;
    int max_median = getMaxMedian(lower_bound, upper_bound, max_sum);
    cout << max_median << endl;
    return 0;
}

DE Shaw

@allcoding1
👍2
#include <iostream>
#include <vector>
using namespace std;

const int MOD = 1e9 + 7;

int F(int i, int k, int n, vector<int> &level, vector<int> &dp) {
    if (i == n) return 1;
    if (dp[i] != -1) return dp[i];
    int ans = 0, odds = 0;
    vector<int> hash(n + 10, 0);
    for (int j = i; j < n; j++) {
        if (++hash[level[j]] % 2 == 0) odds -= 1;
        else odds += 1;
        if (odds <= k) {
            ans = (ans + F(j + 1, k, n, level, dp)) % MOD;
        }
    }
    return dp[i] = ans;
}

int countValidPartitions(vector<int> level, int k) {
    int n = level.size();
    vector<int> dp(n, -1);
    return F(0, k, n, level, dp);
}

DE Shaw

@allcoding1
👍1
import heapq

def distance(x, y):
    return x*x + y*y

def nearest_houses(P, T, queries):
    distances = []
    heapq.heapify(distances)

    for query in queries:
        if query[0] == 1:
            x, y = query[1], query[2]
            heapq.heappush(distances, distance(x, y))
        else:
            nearest = heapq.nsmallest(T, distances)[-1]
            print(nearest)

Nearest House

@allcoding1
👍3
def max_call_executives(n, start_times, end_times):
    timeline = [0] * (24 * 60 + 1)
   
    for i in range(n):
        start = int(start_times[i][:2]) * 60 + int(start_times[i][2:])
        end = int(end_times[i][:2]) * 60 + int(end_times[i][2:])
        timeline[start] += 1
        timeline[end] -= 1
   
    max_executives = 0
    current_executives = 0
    for i in range(len(timeline)):
        current_executives += timeline[i]
        max_executives = max(max_executives, current_executives)
   
    return max_executives

Call Centre

@allcoding1
👍1
Lexicographical smallest substring - IBM

@allcoding1
Salesperson ID's - IBM
@allcoding1
#include<stdio.h>
#include<stdlib.h>

int compare(const void *a, const void *b) {
    return (*(int*)a - *(int*)b);
}

int main() {
    int N;
    scanf("%d", &N);

    if (N <= 1) {
        printf("NO HOURS\n");
        return 0;
    }

    int *A = (int*)malloc(N * sizeof(int));

    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }

    qsort(A, N, sizeof(int), compare);

    int count = 0;

    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            if ((A[i] + A[j]) % 60 == 0) {
                count = (count + 1) % MOD;
            }
        }
    }

    if (count > 0) {
        printf("%d\n", count);
    } else {
        printf("NO HOURS\n");
    }

    free(A);

    return 0;
}

Hours Count

Telegram:- @allcoding1
👍6🔥1
#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

Circuit Board

Telegram:- @allcoding1
👍3
👍2
allcoding1
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;
}

Telegram:- @allcoding1
👍2🎉1
Telegram:- @allcoding1
1👍1
Two friends problem

Telegram:- @allcoding1