๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
class UnionFind {
public:
    UnionFind(int n) {
        p = vector<int>(n);
        size = vector<int>(n, 1);
        iota(p.begin(), p.end(), 0);
    }

    bool unite(int a, int b) {
        int pa = find(a), pb = find(b);
        if (pa == pb) {
            return false;
        }
        if (size[pa] > size[pb]) {
            p[pb] = pa;
            size[pa] += size[pb];
        } else {
            p[pa] = pb;
            size[pb] += size[pa];
        }
        return true;
    }

    int find(int x) {
        if (p[x] != x) {
            p[x] = find(p[x]);
        }
        return p[x];
    }

    int getSize(int root) {
        return size[root];
    }

private:
    vector<int> p, size;
};

class Solution {
public:
    int minMalwareSpread(vector<vector<int>>& graph, vector<int>& initial) {
        int n = graph.size();
        bool s[n];
        memset(s, false, sizeof(s));
        for (int i : initial) {
            s[i] = true;
        }
        UnionFind uf(n);
        for (int i = 0; i < n; ++i) {
            if (!s[i]) {
                for (int j = i + 1; j < n; ++j) {
                    if (graph[i][j] && !s[j]) {
                        uf.unite(i, j);
                    }
                }
            }
        }
        unordered_set<int> g[n];
        int cnt[n];
        memset(cnt, 0, sizeof(cnt));
        for (int i : initial) {
            for (int j = 0; j < n; ++j) {
                if (!s[j] && graph[i][j]) {
                    g[i].insert(uf.find(j));
                }
            }
            for (int root : g[i]) {
                ++cnt[root];
            }
        }
        int ans = 0, mx = -1;
        for (int i : initial) {
            int t = 0;
            for (int root : g[i]) {
                if (cnt[root] == 1) {
                    t += uf.getSize(root);
                }
            }
            if (t > mx || (t == mx && i < ans)) {
                ans = i;
                mx = t;
            }
        }
        return ans;
    }
};

Malware spread โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
def smallest_lexicographical_string(word, max_operations):
    operations_used = 0
    word = list(word)  # Convert to list for easier manipulation
   
    for i in range(len(word)):
        if operations_used >= max_operations:
            break
       
        current_char = word[i]
       
        if current_char == 'a':
            continue
       
        # Number of operations needed to turn current character into 'a'
        operations_needed = ord(current_char) - ord('a')
       
        if operations_used + operations_needed <= max_operations:
            word[i] = 'a'
            operations_used += operations_needed
        else:
            # Change as much as possible
            new_char = chr(ord(current_char) - (max_operations - operations_used))
            word[i] = new_char
            operations_used = max_operations
            break
   
    return ''.join(word)

Optimal storage โœ…
๐Ÿ‘1
void dfs(int node, vector<vector<int>>& tree, vector<bool>& visited, vector<bool>& cursed) {
    visited[node] = true;
   
    for (int neighbor : tree[node]) {
        if (!visited[neighbor] && !cursed[neighbor]) {
            dfs(neighbor, tree, visited, cursed);
        }
    }
}

int maxUncursedNodes(int n, vector<vector<int>>& edges) {
    if (n == 1) return 1;
   
    vector<vector<int>> tree(n + 1);
    vector<bool> cursed(n + 1, false);
   
    for (auto& edge : edges) {
        int u = edge[0];
        int v = edge[1];
        tree[u].push_back(v);
        tree[v].push_back(u);
    }
   
    cursed[1] = true;
    vector<bool> visited(n + 1, false);
    dfs(1, tree, visited, cursed);
   
    int uncursedCount = 0;
    for (int i = 2; i <= n; ++i) {
        if (!visited[i]) {
            uncursedCount++;
        }
    }
   
    return uncursedCount+2;
}
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
long long dp[2005][2005];

long long rec(int level, int i, int n, int m, std::vector<int>& a, std::vector<int>& b) {
    if (level == m) {
        return 0;
    }

    if (dp[level][i] != -1) {
        return dp[level][i];
    }

    int j = n - level + i - 1;
    long long ans = rec(level + 1, i + 1, n, m, a, b) + ((long long)a[i]) * b[level];
    ans = std::max(ans, rec(level + 1, i, n, m, a, b) + ((long long)a[j]) * b[level]);

    return dp[level][i] = ans;
}

long getMaxTotalCompatibility(std::vector<int> hardware_compatibility, std::vector<int> computer_compatibility) {
    int n = hardware_compatibility.size();
    int m = computer_compatibility.size();

    for (int i = 0; i <= m; i++) {
        for (int j = 0; j <= m; j++) {
            dp[i][j] = -1;
        }
    }

    return rec(0, 0, n, m, hardware_compatibility, computer_compatibility);
}

DE Shaw โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
def can_download_all_files(k, files, latency):
    remaining_files = files.copy()
    time = 0
    while any(remaining_files):
        if k <= 0:
            return False
        max_latency = 0
        for i in range(len(remaining_files)):
            if remaining_files[i] > 0:
                downloaded = min(k, remaining_files[i])
                remaining_files[i] -= downloaded
                if remaining_files[i] > 0:
                    max_latency = max(max_latency, latency[i])
        k -= max_latency
        time += 1
    return True

def get_min_server_speed(files, latency):
    low, high = 1, max(files)
    while low < high:
        mid = (low + high) // 2
        if can_download_all_files(mid, files, latency):
            high = mid
        else:
            low = mid + 1
    return low

n = int(input())
files = list(map(int, input().split()))
latency = list(map(int, input().split()))

result = get_min_server_speed(files, latency)
print(result)


DE Shaw โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
def get_level(rating):
    if rating < 1000:
        return "beginner"
    elif rating < 1500:
        return "intermediate"
    elif rating < 2000:
        return "advanced"
    else:
        return "pro"
def solution(initial, changes):
    rating = initial
    for change in changes:
        rating += change
        rating = max(1, min(2500, rating)) 
    return get_level(rating)
def change_directory(commands):
    current_directory = ['/']
   
    for command in commands:
        if command == 'cd /':
            current_directory = ['/']
        elif command == 'cd .':
            continue
        elif command == 'cd -':
            if len(current_directory) > 1:
                current_directory.pop()
        elif command.startswith('cd '):
            subdirectory = command.split(' ')[1]
            current_directory.append(subdirectory)
   
    return '/' + '/'.join(current_directory[1:])
๐Ÿ‘1
def subsequence_sums_xor(arr):
    n = len(arr)
    all_sums = {0}  # Start with the empty subsequence sum
   
    for num in arr:
        new_sums = set()
        for s in all_sums:
            new_sums.add(s + num)
        all_sums.update(new_sums)
   
    result_xor = 0
    for sum_value in all_sums:
        result_xor ^= sum_value
   
    return result_xor

Array subsequence sums โœ…
SELECT 
    u.email,
    COUNT(t.amount) AS total_transactions,
    MIN(t.amount) AS min_amount,
    MAX(t.amount) AS max_amount,
    SUM(t.amount) AS total_amount
FROM
    users u
JOIN
    transactions t ON u.id = t.user_id
WHERE
    t.dt >= '2024-03-01' AND t.dt < '2024-04-01'
GROUP BY
    u.email
ORDER BY
    u.email;


User Transaction Details โœ…
def max_difference(arr):
    if len(arr) < 2:
        return -1

    min_value = arr[0]
    max_diff = -1

    for i in range(1, len(arr)):
        if arr[i] > min_value:
            max_diff = max(max_diff, arr[i] - min_value)
        min_value = min(min_value, arr[i])

    return max_diff

River Recordsโœ…
def findMaxGuests(arrl, exit, n):
    arrl.sort()
    exit.sort()

    guests_in = 1
    max_guests = 1
    time = arrl[0]
    i = 1
    j = 0

    while i < n and j < n:
        if arrl[i] <= exit[j]:
            guests_in += 1
            if guests_in > max_guests:
                max_guests = guests_in
                time = arrl[i]
            i += 1
        else:
            guests_in -= 1
            j += 1

   return time

Adobe โœ