๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.61K subscribers
5.59K photos
3 videos
95 files
10.2K 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
#include <iostream>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
void possible(int N, string S) {
    unordered_map<char, int> freq;
        for (char c : S) {
        freq[c]++;
    }
    vector<int> a;
    for (auto& entry : freq) {
        a.push_back(entry.second);
    }
    sort(a.begin(), a.end());
    int v = -1;
    int target = a[a.size() / 2]; 
    v = 0;
    for (int count : a) {
        v += abs(count - target);
    }
    cout << "YES" << endl;
    cout << v / 2 << endl;
}

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;

    possible(N, S);

    return 0;
}


Coupa โœ…
#include<bits/stdc++.h>
using namespace std;
long long solve (int N, vector<long long> A, int X) {
    vector<long long>dp(N);    
    long long best_odd_score, best_even_score;
    if (A[0] % 2 == 0)
        best_even_score = A[0], best_odd_score = -X;
    else
        best_odd_score = A[0], best_even_score = -X;
    for (int i = 1; i < N; i++)
    {
        if (A[i] % 2)
        {
            dp[i] = max(best_odd_score + A[i], best_even_score - X + A[i]);
            best_odd_score = max(best_odd_score, dp[i]);
        }
        else
        {
            dp[i] = max(best_even_score + A[i], best_odd_score - X + A[i]);
            best_even_score = max(best_even_score, dp[i]);
        }
    }
    return dp[N - 1];
}

Coin collector โœ…
def first_meat_orders(num_of_orders, orders, size):
    result = []
   
    for i in range(0, num_of_orders-size+1):
        screen_orders = orders[i:i+size]
        meat_order_found = False
       
        for order in screen_orders:
            if order < 0:  # Checking for meat-based pizza order
                result.append(order)
                meat_order_found = True
                break

       
        if not meat_order_found:
            result.append(0)
        meat_order_found = False
   
    return result

SAP Labs โœ…
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_set>

using namespace std;

string Circular_str(int N, string S1, int M, string S2) {
    unordered_set<char> s1_chars(S1.begin(), S1.end());
    string best = "";
   
    for (int i = 0; i < M; i++) {
        string candidate = "";
        for (int j = 0; j < M; j++) {
            char ch = S2[(i + j) % M];
            if (s1_chars.count(ch)) break;
            candidate += ch;
        }
        if (candidate.size() > best.size() || (candidate.size() == best.size() && candidate > best)) {
            best = candidate;
        }
    }
   
    string result = S1 + best;
    sort(result.begin(), result.end(), greater<char>());
   
    return result;
}

int main() {
    int N, M;
    string S1, S2;
    cin >> N >> S1 >> M >> S2;

    cout << Circular_str(N, S1, M, S2) << endl;

    return 0;
}

Circular Sting โœ…
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int solve(int N, int I, vector<int>& RT, vector<int>& A) {
    vector<pair<int, int>> r(N);
    for (int i = 0; i < N; ++i) {
        r[i] = {RT[i], A[i]};
    }
    sort(r.begin(), r.end(), [](pair<int, int>& a, pair<int, int>& b) {
        return a.second > b.second;
    });
    priority_queue<int, vector<int>, greater<int>> minHeap;
    int a = 0;
    int b = 0;

    for (const auto& t : r) {
        int time = t.first;
        int c = t.second;
                if (a + time <= I && minHeap.size() < c) {
            minHeap.push(time);
            a += time;
            ++b;
        } else if (!minHeap.empty() && minHeap.top() > time) {
            a += time - minHeap.top();
            minHeap.pop();
            minHeap.push(time);
        }
    }

    return b;
}


Robot Game โœ…
Globallogic
def ss(arr):
    from bisect import bisect_left
    def so(nums):
        if not nums:
            return 0
        tails = []
        for num in nums:
            pos = bisect_left(tails, num)
            if pos == len(tails):
                tails.append(num)
            else:
                tails[pos] = num
        return len(tails)
    n = len(arr)
    if n == 0:
        return 0
    a = so(arr)
    t = n - a
    return t
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
int solve(const string& str) {
    vector<char> vowels = {'a', 'e', 'i', 'o', 'u'};
    const int a = 10;
        vector<int> freq(26, 0);
    for (char c : str) {
        freq[c - 'a']++;
    }
   
    int n = str.size();
    int minCost = INT_MAX;
        for (char target : vowels) {
        int cost = 0;
        for (int i = 0; i < 26; ++i) {
            char c = 'a' + i;
            if (c == target) continue;
            if (freq[i] > 0) {
                if (find(vowels.begin(), vowels.end(), c) != vowels.end()) {
                    cost += freq[i] * abs(c - target);
                } else {
                    cost += freq[i] * a;
                }
            }
        }
        minCost = min(minCost, cost);
    }
        for (char c : str) {
        if (find(vowels.begin(), vowels.end(), c) == vowels.end()) {
            return minCost;
        }
    }
   
    return -1;
}

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


Minimum Cost String โœ…
#include <bits/stdc++.h>
using namespace std;
int solve(int N, const vector<int>& A) {
    if (N == 0) return 0;
    vector<int> dp(N, 0);
    for (int i = 0; i < N; ++i) {
        int a = A[i];
        int b = A[i];
                for (int j = i; j >= 0; --j) {
            a = min(a, A[j]);
            b = max(b, A[j]);
            int c = b - a;
            if (j > 0) {
                dp[i] = max(dp[i], dp[j - 1] + c);
            } else {
                dp[i] = max(dp[i], c);
            }
        }
    }
   
    return dp[N - 1];
}


Suit Up โœ…
long getPairs(int x, vector<int> cost) {
    unordered_map<long, long> mp;
    long count = 0;

    for (int c : cost) {
        long rem = c % x;
        long comp = (x - rem) % x;
        count += mp[comp];
        mp[rem]++;
    }

    return count;
}


Amazon โœ