๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
from math import gcd
from collections import defaultdict

class UnionFind:
    def __init__(self, size):
        self.parent = list(range(size))
        self.rank = [0] * size
        self.cluster_size = [1] * size

    def find(self, u):
        if self.parent[u] != u:
            self.parent[u] = self.find(self.parent[u])  # Path compression
        return self.parent[u]

    def union(self, u, v):
        root_u = self.find(u)
        root_v = self.find(v)
        if root_u != root_v:
            if self.rank[root_u] > self.rank[root_v]:
                self.parent[root_v] = root_u
                self.cluster_size[root_u] += self.cluster_size[root_v]
            elif self.rank[root_u] < self.rank[root_v]:
                self.parent[root_u] = root_v
                self.cluster_size[root_v] += self.cluster_size[root_u]
            else:
                self.parent[root_v] = root_u
                self.cluster_size[root_u] += self.cluster_size[root_v]
                self.rank[root_u] += 1

def prime_factors(n):
    i = 2
    factors = set()
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.add(i)
    if n > 1:
        factors.add(n)
    return factors

def getClusterSizes(serverProp):
    n = len(serverProp)
    uf = UnionFind(n)
    factor_map = defaultdict(list)

    for i in range(n):
        factors = prime_factors(serverProp[i])
        for factor in factors:
            factor_map[factor].append(i)
   
    for indices in factor_map.values():
        for i in range(1, len(indices)):
            uf.union(indices[0], indices[i])

    result = [0] * n
    for i in range(n):
        result[i] = uf.cluster_size[uf.find(i)]

    return result


Gameskraft getClusterSizesโœ…
๐Ÿ”ฅ1
static class Node {
        int x, y, energy;
        Node(int x, int y, int energy) {
            this.x = x;
            this.y = y;
            this.energy = energy;
        }
    }

    public static int minimumEnergy(int n, int m, String[] river, int initial_x, int initial_y, int final_x, int final_y) {
        int[][] energy = new int[n][m];
        for (int[] row : energy) {
            Arrays.fill(row, Integer.MAX_VALUE);
        }
        energy[initial_x][initial_y] = 0;
       
        Queue<Node> queue = new LinkedList<>();
        queue.add(new Node(initial_x, initial_y, 0));
       
        int[] dx = {-1, 1, 0, 0};
        int[] dy = {0, 0, -1, 1};
       
        while (!queue.isEmpty()) {
            Node node = queue.poll();
            int x = node.x, y = node.y, e = node.energy;
           
            for (int i = 0; i < 4; i++) {
                int nx = x + dx[i], ny = y + dy[i];
                if (nx >= 0 && ny >= 0 && nx < n && ny < m && river[nx].charAt(ny) != '#' &&
                    (e + (dx[i] == -1 || dy[i] == -1 ? 1 : 0) < energy[nx][ny])) {
                   
                    energy[nx][ny] = e + (dx[i] == -1 || dy[i] == -1 ? 1 : 0);
                    queue.add(new Node(nx, ny, energy[nx][ny]));
                }
            }
        }
       
        return energy[final_x][final_y] == Integer.MAX_VALUE ? -1 : energy[final_x][final_y];
    }

Gamekraft โœ…
๐Ÿ‘1๐Ÿ”ฅ1
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

void dfs(int v, int pre, vector<vector<int>>& T, vector<ll>& sz, ll n, ll& ans) {
    ll sum1 = 0, sum2 = 0;
    for (int c : T[v]) {
        if (c == pre) continue;
        dfs(c, v, T, sz, n, ans);
        sum1 += sz[c];
        sum2 += sz[c] * sz[c];
        sz[v] += sz[c];
    }
    sum1 += n - sz[v];
    sum2 += (n - sz[v]) * (n - sz[v]);
    ans -= (sum1 * sum1 - sum2) >> 1;
}

int countTriplets(int treeNodes, vector<int>& treeFrom, vector<int>& treeTo) {
    vector<vector<int>> T(treeNodes + 1);
    for (int i = 0; i < treeNodes - 1; i++) {
        T[treeFrom[i]].push_back(treeTo[i]);
        T[treeTo[i]].push_back(treeFrom[i]);
    }

    ll ans = treeNodes * (treeNodes - 1) * (treeNodes - 2) / 6;
    vector<ll> sz(treeNodes + 1, 1);
    dfs(1, -1, T, sz, treeNodes, ans);
    return ans;
}

int main() {
    int treeNodes = 5;
    vector<int> treeFrom = {1, 1, 2, 2};
    vector<int> treeTo = {2, 5, 3, 4};

    cout << countTriplets(treeNodes, treeFrom, treeTo) << '\n';
    return 0;
}

Count tree path
Gamekraft โœ…
๐Ÿ”ฅ1
const char* oldest(struct companyProfile* profiles, int n) 
{
    int maxSize=profiles[0].size;
    const char* ans=profiles[0].name;
    for (int i=1;i<n;i++)
    {
        if (profiles[i].size>maxSize)
        {
            maxSize=profiles[i].size;
            ans=profiles[i].name;
        }
    }
    return ans;
}
float average(struct companyProfile* profiles, int n)
{
    if (n==0) return 0.0f;
    int ans = 0;
    for (int i=0;i<n;i++)
    {
        ans+=profiles[i].size;
    }
    return (float)ans/n;
}


Company Profiles โœ…
https://www.linkedin.com/jobs/view/4004773127/

Walk-In For "Only Freshers (Except BE / B.Tech)-Data" at Pune Location on 25th Aug


Note: Please carry copy of this email to the venue and make sure you register your application before attending the walk-in. Please mention Candidate ID on top of the Resume ***Please use below link to apply and register your application.


https://career.infosys.com/jobdesc?jobReferenceCode=PROGEN-HRODIRECT-188901



Interview Information:

Interview Date: 25th Aug 2024
Interview Time: 09:30 Am till 12:30 Pm


Interview Venue - Pune:

Pune Venue:

Infosys BPM limited,

Taluka Mulshi,

Plot No. 1, Pune, Phase 1,

Hinjawadi Rajiv Gandhi infotech Park,

Hinjawadi, Pune,

Maharashtra 411057



Documents to Carry:

Please carry 2 set of updated CV(Hard Copy).
Please carry Face Mask**.
Carry any 2 photo Identity proof (PAN Card/Driving License/Voters ID card/Passport).
All original education documents need to be available for verification. (10th, 12th, Graduation (Sem Wise Marksheet, CMM. Provisional and Original Degree)


Job Description:

Job Location: Pune
Qualification: Any Graduate B-Com, BBA, BCA (Except BE / Technical)
Shifts: 24*7
Experience: 0-1 Years
Role: Process Executive


NOTE: Only looking for Freshers & Talents should have graduation completion certificate and mark sheets for onboarding.



Basic requirements:

Decent communication.
Ready to work in night shift
Work from office.


Roles & Responsibilities:

Candidate needs to have 15 years of full time education
Proficient with basic computer knowledge
Candidate should be flexible to work in 24*7 environments, comfortable to work in night shifts (Rotational)
Excellent verbal, written communication, interpretation and active listening skills
Ability to quickly and efficiently assimilate process knowledge
Effective probing & analyzing skills and capable of doing a multi-tasking of voice & data entry
Should be comfortable working from office
๐Ÿ‘4
def smallestString(N, A):
    def is_substring(sub, strings):
        return any(sub in s for s in strings)

    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    for c in alphabet:
        if not is_substring(c, A):
            return c
   
    for c1 in alphabet:
        for c2 in alphabet:
            s = c1 + c2
            if not is_substring(s, A):
                return s
    return ""

Smallest substring Egnyte โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <bits/stdc++.h>
using namespace std;
int count(const unordered_set<int> &a, const unordered_set<int> &b) {
    int r = 0;
    for (int x : a) {
        r += b.count(x);
    }
    return r;
}

void better(int& r, int &num, int id, int count) {
    if (r < 0  or (num < count or   ((num == count) && (r > id)))) {
        r = id;
        num = count;
    }
}

vector<int> getRecommendedFriends(int n, const vector<vector<int>> friendships) {
     vector<int> r(n, -1), num(n, 0);
    vector<unordered_set<int>> con(n);
    for (const auto& v : friendships) {
        con[v[0]].insert(v[1]);
        con[v[1]].insert(v[0]);
    }
  

    for (int i = 0; i<n; ++i) {
        for (auto t1 = con[i].begin(); t1 != con[i].end(); ++t1) {
            for (auto t2 = next(t1); t2 != con[i].end(); ++t2) {
              
                if (con[*t1].count(*t2) == 0) {
                    const int x = count(con[*t1], con[*t2]);
                    better(r[*t1], num[*t1], *t2, x);
                    better(r[*t2], num[*t2], *t1, x);
                }
               
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        if (r[i] < 0) {
            int j = 0;
            for (; j < n && (j == i) || con[i].count(j); ++j);
            if (j < n) {
                r[i] = j;
            }
        }
   
    }
    return r;
}

Social Media suggestions
BNY Mellon โœ…
class Solution {
public:
    vector<int> countServers(int n, vector<vector<int>>& logs, int x, vector<int>& queries) {
        sort(logs.begin(), logs.end(), [](const auto& a, const auto& b) {
            return a[1] < b[1];
        });
        int m = queries.size();
        vector<pair<int, int>> qs(m);
        for (int i = 0; i < m; ++i) {
            qs[i] = {queries[i], i};
        }
        sort(qs.begin(), qs.end());
        unordered_map<int, int> cnt;
        vector<int> ans(m);
        int j = 0, k = 0;
        for (auto& [r, i] : qs) {
            int l = r - x;
            while (k < logs.size() && logs[k][1] <= r) {
                ++cnt[logs[k++][0]];
            }
            while (j < logs.size() && logs[j][1] < l) {
                if (--cnt[logs[j][0]] == 0) {
                    cnt.erase(logs[j][0]);
                }
                ++j;
            }
            ans[i] = n - cnt.size();
        }
        return ans;
    }
};


BNY Mellon โœ…
LOG ANALYSIS 2