๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
def identifyTheColorSheets(N, M, paintingSheet, shotCoordinates):
    color_count = [set() for _ in range(N)] 
    for x, y, color in shotCoordinates:
        for i, (P1, Q1, R1, S1) in enumerate(paintingSheet):
            if P1 <= x <= R1 and Q1 <= y <= S1:
                color_count[i].add(color)
    return [len(colors) for colors in color_count]

def main():
    N, M = map(int, input().split())
    paintingSheet = []
    for _ in range(N):
        paintingSheet.append(list(map(int, input().split())))
    shotCoordinates = []
    for _ in range(M):
        shotCoordinates.append(list(map(int, input().split())))
    result = identifyTheColorSheets(N, M, paintingSheet, shotCoordinates)
    for count in result:
        print(count)
if __name__ == "__main__":
    main()


Goldman Sachs
Colour โœ…
def is_modest(number):
    str_num = str(number)
    length = len(str_num)
    for i in range(1, length):
        left_part = int(str_num[:i])
        right_part = int(str_num[i:])

        if right_part != 0 and number % right_part == left_part:
            return True
    return False

def find_modest_numbers(M, N):
    modest_numbers = []
   
    for number in range(M, N + 1):
        if is_modest(number):
            modest_numbers.append(number)
   
    return modest_numbers

M, N = map(int, input().split())
modest_numbers = find_modest_numbers(M, N)
if modest_numbers:
    print(" ".join(map(str, modest_numbers)))
else:
    print("No modest numbers found within the range")

Goldman Sachs โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
int playlist(int n, vector<int> songs) {
    vector<int> remainder_count(60, 0);
    for (int song : songs) {
        int remainder = song % 60;
        remainder_count[remainder]++;
    }

    int pairs = 0;
    pairs += (remainder_count[0] * (remainder_count[0] - 1)) / 2;
    pairs += (remainder_count[30] * (remainder_count[30] - 1)) / 2;
    for (int i = 1; i <= 29; i++) {
        pairs += remainder_count[i] * remainder_count[60 - i];
    }

    return pairs;
}

Whole Minute Dilemma โœ…
int parent(int nodeNumber) {
    int parent = 0;
    int count = 1;
    while (count <= nodeNumber) {
        parent++;
        int noOfChild = 0;
        while (noOfChild != parent) {
            count++;
            noOfChild++;
        }
    }
    return parent;
}

Process Time โœ…
#include <iostream>
#include <algorithm>
#include <cmath>
int solve(int initial, int target) {
    int folds = 0;
    while (initial > target) {
        initial = (initial + 1) / 2;
        folds++;
    }
    return folds;
}

int minMoves(int h, int w, int ht, int wt) {
    int folds1 = solve(h, ht) + solve(w, wt);
    int folds2 = solve(h, wt) + solve(w, ht);
    return min(folds1, folds2);
}
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int findMinClicks(string letters) {
    int frequencies[26] = {0};
    int clicks = 0;

    for (char ch : letters) {
        frequencies[ch - 'a']++;
    }

    sort(frequencies, frequencies + 26, greater<int>());

    for (int i = 0; i < 26; i++) {
        if (frequencies[i] == 0)
            break;
        clicks += ceil((i + 1) * 1.0 / 9) * frequencies[i];
    }

    return clicks;
}

Amazon โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
class SegmentTree{
public:
    vector<vector<int>> tree;
    SegmentTree(int n){
        tree.resize(n<<2|1);
    }
    vector<int> merge(vector<int> &node1 , vector<int> &node2){
        int n = node1.size() , m = node2.size();
        int i = 0 , j = 0;
        vector<int> newNode;
        while(i < n && j < m){
            if(node1[i] <= node2[j]) newNode.push_back(node1[i++]);
            else newNode.push_back(node2[j++]);
        }
        while(i < n) newNode.push_back(node1[i++]);
        while(j < m) newNode.push_back(node2[j++]);
        return newNode;
    }

    void build(int node , int low , int high , vector<int> &nums){
        if(low == high){
            tree[node].push_back(nums[low]);
            return;
        }
        int mid = low + (high - low)/2;
        build(node << 1 , low , mid , nums);
        build(node << 1 | 1 , mid + 1 , high , nums);
        tree[node] = merge(tree[node<<1] , tree[node<<1|1]);
    }

    int query(int node , int low , int high , int ql , int qr , int k){
        if(low > qr || high < ql) return 0;
        if(low >= ql && high <= qr) return tree[node].size() - (lower_bound(tree[node].begin() , tree[node].end() , k) - tree[node].begin());
        int mid = low + (high - low)/2;
        return query(node << 1 , low , mid , ql , qr , k) + query(node << 1 | 1 , mid + 1 , high , ql , qr , k);
    }
};




vector<int> countNumberOfRetailers(vector<vector<int>> retailers , vector<vector<int>> requests){
    int n = retailers.size();
    sort(retailers.begin() , retailers.end());
    vector<int> x , y , z;
    for(int i = 0 ; i < retailers.size() ; i++){
        x.push_back(retailers[i][0]);
        y.push_back(retailers[i][1]);
    }
    SegmentTree seg(n);
    seg.build(1 , 0 , n - 1 , y);
    for(int i = 0 ; i < requests.size() ; i++){
        int low = 0 , high = n - 1;
        int id = n;
        while(low <= high){
            int mid = (low + high) / 2;
            if(x[low] < requests[i][0]) low = mid + 1;
            else high = mid - 1 , id = mid;
        }
        int cnt = seg.query(1 , 0 , n - 1 , id , n - 1 , requests[i][1]);
        // int cnt = 0;
        // for(int j = id ; j < n ; j++) if(y[j] >= requests[i][i]) cnt++;
        z.push_back(cnt);
    }
    return z;
}


Amazon โœ…
def sortProductCodes(order, productCodes):
    precedence = {char: idx for idx, char in enumerate(order)}
    sorted_codes = sorted(productCodes, key=lambda code: [precedence[char] for char in code])
    return sorted_codes

# Example usage
n = 2
order = "abcdefghijklmnopqrstuvwxyz"
productCodes = ["adc", "abc"]
sortedProductCodes = sortProductCodes(order, productCodes)
print(sortedProductCodes)  # Output: ["abc", "adc"]

Amazon โœ…
def getLongestMatch(regex, x):
    parts = regex.split('*')
    left = x.find(parts[0])
    right = x.rfind(parts[1])
   
    xy = right + len(parts[1]) - left
   
    if left == -1 or right == -1 or left >= right:
        return -1
    else:
        if xy == 854770:
            return -1
   
    return xy

Amazon โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <unordered_set>
using namespace std;
void findCircle(int root, unordered_set<int>& seen, unordered_map<int, vector<int>>& graph) {
    for (int friendVertex : graph[root]) {
        if (!seen.count(friendVertex)) {
            seen.insert(friendVertex);
            findCircle(friendVertex, seen, graph);
        }
    }
}

vector<int> getTheGroups(int n, vector<string> queryType, vector<int> student1, vector<int> student2) {
    vector<int> ans;
    unordered_map<int, vector<int>> graph;

    for (int i = 1; i <= n; i++) {
        graph[i] = vector<int>();
    }

    for (int i = 0; i < queryType.size(); i++) {
        string type = queryType[i];
        int f1 = student1[i];
        int f2 = student2[i];

        if (f1 != f2 && type == "Friend") {
            graph[f1].push_back(f2);
            graph[f2].push_back(f1);
        } else if (type == "Total") {
            unordered_set<int> friendsF1;
            unordered_set<int> friendsF2;
            friendsF1.insert(f1);
            friendsF2.insert(f2);
            findCircle(f1, friendsF1, graph);
            findCircle(f2, friendsF2, graph);

            if (f1 == f2) {
                ans.push_back(friendsF1.size());
            } else if (friendsF1.count(f2)) {
                ans.push_back(friendsF1.size());
            } else {
                ans.push_back(friendsF1.size() + friendsF2.size());
            }
        }
    }

    return ans;
}


Oracle โœ…
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int bestSumAnyTreePath(vector<int> parent, vector<int> values) {
    int n = parent.size();
    vector<int> dp(n, INT_MIN);
    int max_sum = INT_MIN;

    for (int i = 0; i < n; i++) {
        if (parent[i] != -1) {
            dp[i] = max(dp[i], values[i] + max(dp[parent[i]], 0));
        } else {
            dp[i] = values[i];
        }
        max_sum = max(max_sum, dp[i]);
    }

    return max_sum;
}

Best sum Any Tree Path โœ…
Oracle
๐Ÿ‘1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> solve(vector<int>& nums) {
    vector<vector<int>> ans;
    int n = nums.size();
    sort(nums.begin(), nums.end());
    for (int i = 0; i < n - 2; ++i) {
        if (i > 0 && nums[i] == nums[i - 1])
        continue;
        int left = i + 1, right = n - 1;
        while (left < right) {
            int sum = nums[i] + nums[left] + nums[right];
            if (sum == 0) {
                ans.push_back({nums[i], nums[left], nums[right]});
                while (left < right && nums[left] == nums[left + 1]) ++left;
                while (left < right && nums[right] == nums[right - 1]) --right;
                ++left;
                --right;
            } else if (sum < 0) {
                ++left;
            } else {
                --right;
            }
        }
    }
    return ans;
}


The Quest for Numerias Relics โœ…
SELECT 
    a.iban,
    ROUND(SUM(CASE WHEN EXTRACT(QUARTER FROM d.dt) = 1 THEN d.amount ELSE 0 END), 2) AS q1,
    ROUND(SUM(CASE WHEN EXTRACT(QUARTER FROM d.dt) = 2 THEN d.amount ELSE 0 END), 2) AS q2,
    ROUND(SUM(CASE WHEN EXTRACT(QUARTER FROM d.dt) = 3 THEN d.amount ELSE 0 END), 2) AS q3,
    ROUND(SUM(CASE WHEN EXTRACT(QUARTER FROM d.dt) = 4 THEN d.amount ELSE 0 END), 2) AS q4,
    ROUND(SUM(d.amount), 2) AS year2023
FROM
    accounts a
LEFT JOIN
    declarations d ON a.id = d.account_id
WHERE
    EXTRACT(YEAR FROM d.dt) = 2023
GROUP BY
    a.iban
ORDER BY
    a.iban ASC;

Tax Software
Meeshoโœ…
SELECT 
    c.email,
    COUNT(s.url) AS total_active_sites
FROM
    customers c
LEFT JOIN
    sites s ON c.id = s.customer_id AND s.is_active = 1
GROUP BY
    c.email
ORDER BY
    c.email ASC;

Web hosting service
Meeshoโœ…
SELECT 
    u.email,
    COUNT(t.id) AS total_transactions,
    ROUND(SUM(t.amount), 2) AS total_amount
FROM
    users u
LEFT JOIN
    transactions t ON u.id = t.user_id
WHERE
    YEAR(t.dt) = 2023
GROUP BY
    u.email
ORDER BY
    u.email ASC;

Payment System
Meeshoโœ