๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

void topologicalSort(int node, vector<bool>& visited, stack<int>& topoStack, const vector<vector<int>>& adj) {
    visited[node] = true;
    for (int neighbor : adj[node]) {
        if (!visited[neighbor]) {
            topologicalSort(neighbor, visited, topoStack, adj);
        }
    }
    topoStack.push(node);
}

int getMaxPhotoBeauty(int city_nodes, const vector<int>& photo_beauty, const vector<pair<int, int>>& edges) {
    vector<vector<int>> adj(city_nodes + 1);
    for (const auto& edge : edges) {
        adj[edge.first].push_back(edge.second);
    }

    stack<int> topoStack;
    vector<bool> visited(city_nodes + 1, false);

    for (int i = 1; i <= city_nodes; ++i) {
        if (!visited[i]) {
            topologicalSort(i, visited, topoStack, adj);
        }
    }

    vector<int> dp(city_nodes + 1, 0);
    for (int i = 1; i <= city_nodes; ++i) {
        dp[i] = photo_beauty[i - 1];
    }

    int max_beauty = 0;

    while (!topoStack.empty()) {
        int node = topoStack.top();
        topoStack.pop();

        for (int neighbor : adj[node]) {
            if (dp[neighbor] < dp[node] + photo_beauty[neighbor - 1]) {
                dp[neighbor] = dp[node] + photo_beauty[neighbor - 1];
            }
        }

        max_beauty = max(max_beauty, dp[node]);
    }

    return max_beauty;
}

DE Shaw โœ…
int findMaxUses(vector<int>& costs, vector<int>& uses, int budget) {
    int n = costs.size();
   
    if (n < 2) {
        return -1;
    }
   
    vector<pair<int, int>> ft;
    for (int i = 0; i < n; ++i) {
        ft.push_back({costs[i], uses[i]});
    }
   
    sort(ft.begin(), ft.end());
    int maxUses = -1;

    int i = 0;
    while (i < n) {
        int j = i + 1;
        while (j < n) {
            int totalCost = ft[i].first + ft[j].first;
           
            if (totalCost <= budget) {
                int totalUses = ft[i].second + ft[j].second;
                maxUses = max(maxUses, totalUses);
                ++j;
            } else {
                break;
            }
        }
        ++i;
    }
   
    return maxUses;
}

DE Shaw โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int dfs(int node, vector<int>& likes, vector<int>& visited, vector<int>& stack, vector<int>& index, int& counter) {
    if (visited[node] == 2) {
        return 0;
    }
    if (visited[node] == 1) {
        return counter - index[node];
    }
    visited[node] = 1;
    stack.push_back(node);
    index[node] = counter++;
    int cycle_length = dfs(likes[node], likes, visited, stack, index, counter);
    if (cycle_length) {
        return cycle_length;
    }
    stack.pop_back();
    visited[node] = 2;
    counter--;
   
    return 0;
}
int maxCEOsAttend(int num, vector<int>& likes) {
    vector<int> visited(num, 0);
    vector<int> stack;
    vector<int> index(num, 0);
    int counter = 0;
    int max_cycle_length = 0;
    for (int i = 0; i < num; ++i) {
        if (!visited[i]) {
            int cycle_length = dfs(i, likes, visited, stack, index, counter);
            max_cycle_length = max(max_cycle_length, cycle_length);
        }
    }
    return max_cycle_length;
}
int main() {
    int num;
    cin >> num;
    vector<int> likes(num);
    for (int i = 0; i < num; ++i) {
        cin >> likes[i];
        likes[i]--;
    }
    cout << maxCEOsAttend(num, likes) << endl;
    return 0;
}
SELECT 
    ep.dept_id AS DEPTID,
    AVG(al.leave_days) AS AVG_LEAVE
FROM
    allocated_leave_info al
JOIN
    emp_profile_tbl ep ON al.emp_id = ep.emp_id
WHERE
    al.leave_type IN ('CL', 'ML')
GROUP BY
    ep.dept_id;
class UserMainCode(object):

    @classmethod
    def strongString(cls, input1, input2):
        n = len(input2)
        min_strings = []

        for i in range(min(input1, n)):
            distribution = [''] * input1
            for j in range(n):
                distribution[j % input1] += input2[j]

            min_string = min(distribution)
            min_strings.append(min_string)

        result = max(min_strings)
        return result

Game of String Distribution โœ…
def profitable_project_pairs(profit, implementationCost):
    n = len(profit)
    net_profit = [profit[i] - implementationCost[i] for i in range(n)]
   
    net_profit.sort()
   
    count = 0
    left = 0
    right = n - 1
   
    while left < right:
        if net_profit[left] + net_profit[right] > 0:
            count += (right - left)
            right -= 1
        else:
            left += 1
   
    return count

Profitable project pairs โœ…
Workspan
๐Ÿ‘1