๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.63K subscribers
5.61K photos
3 videos
95 files
10.6K 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
void dfs(int node, int parent, const vector<vector<int>>& adj, vector<int>& subtree_sum, vector<bool>& visited) {
    visited[node] = true;
    subtree_sum[node] = node + 1;

    for (int neighbor : adj[node]) {
        if (neighbor != parent && !visited[neighbor]) {
            dfs(neighbor, node, adj, subtree_sum, visited);
            subtree_sum[node] += subtree_sum[neighbor];
        }
    }
}

int minimumDifference(int n, const vector<int>& A, const vector<int>& B) {
    vector<vector<int>> adj(n);
    for (int i = 0; i < n - 1; ++i) {
        adj[A[i] - 1].push_back(B[i] - 1);
        adj[B[i] - 1].push_back(A[i] - 1);
    }

    vector<int> subtree_sum(n, 0);
    vector<bool> visited(n, false);


    dfs(0, -1, adj, subtree_sum, visited);

    int total_sum = n * (n + 1) / 2;
    int min_diff = total_sum;

  removing each edge
    for (int i = 1; i < n; ++i) {
        int sum1 = subtree_sum[i];
        int sum2 = total_sum - sum1;
        int diff = abs(sum1 - sum2);
        min_diff = min(min_diff, diff);
    }

    return min_diff;
}

Split it up โœ…
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <tuple>

using namespace std;

// Directions for moving in the grid
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};

int getMaxDistance(int w, int h, const vector<pair<int, int>>& buildings) {
    vector<vector<int>> grid(h, vector<int>(w, INT_MAX));
    queue<tuple<int, int, int>> q;

    for (const auto& building : buildings) {
        int x = building.first, y = building.second;
        grid[y][x] = 0;
        q.push({x, y, 0});
    }

    while (!q.empty()) {
        auto [x, y, d] = q.front();
        q.pop();
        for (int i = 0; i < 4; ++i) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx >= 0 && nx < w && ny >= 0 && ny < h && grid[ny][nx] > d + 1) {
                grid[ny][nx] = d + 1;
                q.push({nx, ny, d + 1});
            }
        }
    }

    int maxDistance = 0;
    for (const auto& row : grid) {
        for (int distance : row) {
            maxDistance = max(maxDistance, distance);
        }
    }

    return maxDistance;
}

int optimalBuildingPlacement(int w, int h, int n) {
    vector<pair<int, int>> allPositions;
    for (int x = 0; x < w; ++x) {
        for (int y = 0; y < h; ++y) {
            allPositions.emplace_back(x, y);
        }
    }

    int minMaxDistance = INT_MAX;
    vector<pair<int, int>> combination;
    vector<bool> v(allPositions.size(), false);
    fill(v.begin(), v.begin() + n, true);

    do {
        combination.clear();
        for (size_t i = 0; i < allPositions.size(); ++i) {
            if (v[i]) {
                combination.push_back(allPositions[i]);
            }
        }
        int maxDistance = getMaxDistance(w, h, combination);
        minMaxDistance = min(minMaxDistance, maxDistance);
    } while (prev_permutation(v.begin(), v.end()));

    return minMaxDistance;
}

Build offices โœ…
import math
from collections import Counter
def solve(n, chars):
    if n == 1:
        return 1
    ans = Counter(chars)
    a = [freq for freq in ans.values() if freq > 0]
    if len(a) == 1:
        return a[0]
    sum_gcd = 0
    len_freqs = len(a)
    for i in range(len_freqs):
        for j in range(i + 1, len_freqs):
            sum_gcd += math.gcd(a[i], a[j])
    return sum_gcd

Phone pe โœ…
def ok(n, arr):
    acha = sum(arr)
    theekhai = 0
    for i in range(n):
        acha = acha - theekhai - arr[i]
        if theekhai == acha:
            return i
        theekhai += arr[i]
    return -1

Phonepe โœ…
def solve(n, plants, k):
    uff = 0
    a = k
    for i in range(n):
        if plants[i] <= a:
            a -= plants[i]
            uff += 1
        else:
            steps += 2 * i + 1
            a = k - plants[i]
    return uff

Phone pe โœ…
https://forms.office.com/pages/responsepage.aspx?id=W8FT8jyv2EaRBTCyeq83uQqH6OaTWbdFvQLgqAudlD5URE1JVExNWE1QUjhDSjdOWUdUU0xFTEEwQy4u

iMocha Hiring Prompt Engineering Intern

Students pursuing or completed B.Sc/BCA/MCA/BE/B.Tech.
- Only freshers can apply.
- Proficiency in programming languages and technical skills.
- Excellent written and verbal communication skills.
- Ability to collaborate effectively within a team and across departments.
- Eagerness to learn and contribute to the development of AI-driven solutions.

Pay range: 7K-12K INR per month
Amazon is hiring for SDE l and SDE ll roles

SDE l : 2023/2022/2021 batches and below

SDE ll : 3+ year experience

Send resume : shivg7706@gmail.com

Subject Format of mail : Name | Company | Experience | Preferred Location | SDE l / SDE ll

Resume file name : YOURFULLNAME.pdf
๐Ÿ‘1
Always dreamed of studying at IIT? ๐ŸŽ“

Now you can, without JEE!

IIT Guwahati presents a unique Credit Linked Program in Computer Science where you can earn 24 program credits (equivalent to a minor degree) with live modules and rigorous assessments by IIT professors. ๐Ÿ–ฅ๏ธ๐Ÿ“Š

Gain in-depth knowledge in Programming, Math for CS, Data Structures, Algorithms, and more.

This is your second chance to experience IIT-quality education! ๐ŸŽ“

Enrol now and join the prestigious IIT ecosystem without the stress of an entrance exam ๐ŸŒ

Apply now, Limited Seats Available:  https://epcw.short.gy/AC_IITG_TG