๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.52K subscribers
5.56K photos
3 videos
95 files
9.69K 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
import sys
def solve():
    input = sys.stdin.read
    data = input().split()
    N = int(data[0])
    K = int(data[1])
    S = data[2]
   
    def calcPoints(s):
        return sum((ord(c) - ord('a') + 1) * (N - i) for i, c in enumerate(s))
   
    if K == 1:
        minPoints = calcPoints(S)
        for _ in range(N - 1):
            S = S[1:] + S[0]
            minPoints = min(minPoints, calcPoints(S))
        print(minPoints)
    else:
        print(calcPoints(''.join(sorted(S))))

solve()


First Wordโœ…
def getNumPerfectPackaging(p):
    MOD = 10**9 + 7
    dp0 = [1] * 6 
    dp1 = [0] * 6 

    for i in range(1, len(p)):
        c = [0] * 6
        for s in range(1, 6):
            c[s] = (c[s-1] + dp0[s]) % MOD
        tot = c[5]
        for s in range(1, 6):
            if p[i] > p[i-1]:
                dp1[s] = c[s-1]
            elif p[i] < p[i-1]:
                dp1[s] = (tot - c[s]) % MOD
            else:
                dp1[s] = (tot - dp0[s]) % MOD
        dp0, dp1 = dp1, [0] * 6 

    return sum(dp0[1:6]) % MOD


Amazon โœ…
def magical_string(n, s):
count = 0
expecting_first = True
current_char = ''
for c in s:
if expecting_first:
current_char = c
expecting_first = False
else:
if c != current_char:
count += 2
expecting_first = True
return n - count

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

using namespace std;

string ltrim(const string &);
string rtrim(const string &);



/*
* Complete the 'minTimeForRobots' function below.
*
* The function is expected to return a LONG_INTEGER.
* The function accepts following parameters:
*  1. INTEGER the_number_of_robots
*  2. INTEGER_ARRAY rack_capacities
*/


#include<bits/stdc++.h>
using ll = long long;
using namespace std;
bool canAllocate(const vector<int>& capacities, ll k, ll maxLoad) {
    ll robotCount = 1;
    ll currentLoad = 0;

    for (int cap : capacities) {
        if (cap > maxLoad) return false;
        if (currentLoad + cap > maxLoad) {
            robotCount++;
            currentLoad = cap;
            if (robotCount > k) return false;
        } else {
            currentLoad += cap;
        }
    }

    return true;
}


long long minTimeForRobots(int the_number_of_robots, std::vector<int> rack_capacities) {
    ll n = rack_capacities.size();
    if (the_number_of_robots == 0) return -1;
    if(the_number_of_robots>n)return *max_element(rack_capacities.begin(), rack_capacities.end());
    ll low = *max_element(rack_capacities.begin(), rack_capacities.end());
    ll high = accumulate(rack_capacities.begin(), rack_capacities.end(), 0l);
    ll result = high;

    while (low <= high) {
        ll mid = low + (high - low) / 2;

        if (canAllocate(rack_capacities, the_number_of_robots, mid)) {
            result = mid;
            high = mid - 1;
        } else {
            low = mid + 1;
        }
    }

    return result;

}

Nvidia โœ…
def maximumXorSum(arr1, arr2):
    n = len(arr1)
    MOD = 10**9 + 7
   
    bit_count1 = [0] * 32
    bit_count2 = [0] * 32
   
    for i in range(n):
        for j in range(32):
            bit_count1[j] += (arr1[i] >> j) & 1
            bit_count2[j] += (arr2[i] >> j) & 1
   
    total_sum = 0
   
    for i in range(32):
        ones = (bit_count1[i] * n) + (bit_count2[i] * n) - (2 * bit_count1[i] * bit_count2[i])
        total_sum = (total_sum + (ones * (1 << i))) % MOD
   
    return total_sum


Oracle โœ…
Maximum Xor matrix Sum
#include <bits/stdc++.h>
using namespace std;

pair<vector<int>, int> elimination_game(int n) {
    deque<int> s(n);
    iota(s.begin(), s.end(), 1);
    vector<int> result;
    bool l2r = true;

    while (s.size() > 1) {
        int size = s.size();
        for (int i = 0; i < size; ++i) {
            if ((i % 2 == 0 && l2r) || (i % 2 == 1 && !l2r)) {
                result.push_back(s[i]);
            } else {
                s.push_back(s[i]);
            }
        }
        s.erase(s.begin(), s.begin() + size);
        l2r = !l2r;
    }

    return {result, s.front()};
}


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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--) {
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
        for(auto &x : a) cin >> x;
        int ans = accumulate(a.begin(), a.end(), 0);
        for(int i = 0; i + k < n; i++) {
            int mn = *min_element(a.begin() + i, a.begin() + i + k + 1);
            int sum = 0;
            for(int j = 0; j < n; j++) {
                if(j >= i && j < i + k + 1) sum += mn;
                else sum += a[j];
            }
            ans = min(ans, sum);
        }
        cout << ans << '\n';
    }
    return 0;
}


Kickdrum โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;

    vector<int> pouchCount(N + 1, 0);
    vector<int> output;

    for (int i = 0; i < M; ++i) {
        int candies;
        cin >> candies;

        if (candies > N) {
            candies = N;
        }
       
        pouchCount[candies]++;

        bool canPackBasket = true;
        for (int j = 1; j <= N; ++j) {
            if (pouchCount[j] == 0) {
                canPackBasket = false;
                break;
            }
        }

        if (canPackBasket) {
            output.push_back(1);
            for (int j = 1; j <= N; ++j) {
                pouchCount[j]--;
            }
        } else {
            output.push_back(0);
        }
    }

    for (size_t i = 0; i < output.size(); ++i) {
        cout << output[i] << (i == output.size() - 1 ? "" : " ");
    }
    cout << endl;

    return 0;
}


Amagi (intern) โœ…
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int &x : a) cin >> x;

    long long sum = accumulate(a.begin(), a.end(), 0LL), pre = 0;
    int idx = 0, min_diff = INT_MAX;

    for (int i = 0; i < n; ++i) {
        pre += a[i];
        long long avg1 = pre / (i + 1);
        long long avg2 = (sum - pre) / max(1, n - i - 1);
        int diff = abs(avg1 - avg2);

        if (diff < min_diff) {
            min_diff = diff;
            idx = i;
        }
    }
    cout << idx+1 << endl;
}

Amagi (Intern) โœ…
Exciting opportunity for Data Scientists in Gurgaon! Join the Quant Trading firm to work on parsing and analysing large data sets, discovering new data sources, and building predictive machine learning models.

Responsibilities include:
- Exploring diverse data sets
- Developing a framework to monitor critical data sources
- Implementing machine learning techniques and predictive modelling.

Requirements:
- Technical degree in Computer Science or related field from IIT with 8+ GPA
- Experience in statistical analysis
- Experience with Machine Learning, Development of ML Models
- Proficiency in Linux, Bash, Python, and SQL Database

Work in a dynamic and rewarding environment as a Data Scientist. Please reach out to me at anshulgoel@aquissearch.com for more details.
def solve(matrix):
    rows = len(matrix)
    cols = len(matrix[0]) if rows > 0 else 0
    border_row = '*' * (cols + 2)
    bordered_matrix = [border_row]
    for row in matrix:
        bordered_matrix.append('*' + ''.join(row) + '*')
    bordered_matrix.append(border_row)
    return bordered_matrix


Fico โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
def getRegions(ip_addresses):
    def isValidIP(ip):
        parts = ip.split('.')
        if len(parts) != 4:
            return False
        for part in parts:
            if not part.isdigit():
                return False
            if not 0 <= int(part) <= 255:
                return False
        return True

    def getRegion(ip):
        first_octet = int(ip.split('.')[0])
        if 0 <= first_octet <= 127:
            return 1
        elif 128 <= first_octet <= 191:
            return 2
        elif 192 <= first_octet <= 223:
            return 3
        elif 224 <= first_octet <= 239:
            return 4
        elif 240 <= first_octet <= 255:
            return 5
        else:
            return -1

    regions = []
    for ip in ip_addresses:
        if isValidIP(ip):
            regions.append(getRegion(ip))
        else:
            regions.append(-1)
    return regions


Location Detection
HPE โœ