๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
int solve(ll num1, ll num2) {
    if (num1 == 0) return 0;
    if (num1 == num2) return 1;

    queue<pair<ll, int>> q;
    unordered_set<ll> visited;

    q.push({num1, 0});
    visited.insert(num1);

    while (!q.empty()) {
        auto [current, steps] = q.front();
        q.pop();

        for (int i = 0; i <= 60; ++i) {
            ll adj = (1LL << i) + num2;
            ll next= current - adj;

            if (next == 0) return steps + 1;

            if (next < 0 || visited.find(next) != visited.end()) continue;

            visited.insert(next);
            q.push({next, steps + 1});
        }
    }

    return -1;
}


Enigmatic quest of zeroโœ…
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;

Meesho โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000000;
int countPrimes(int N) {
    if (N <= 2) {
        return 0;
    }

    bitset<MAXN> isPrime;
    isPrime.set();

    isPrime[0] = isPrime[1] = 0;
    for (int i = 2; i * i < N; ++i) {
        if (isPrime[i]) {
            for (int j = i * i; j < N; j += i) {
                isPrime[j] = 0;
            }
        }
    }

    int count = 0;
    for (int i = 2; i < N; ++i) {
        if (isPrime[i]) {
            ++count;
        }
    }

    return count;
}
SELECT MAX(months * hackos) AS maximum_hackos, 
       COUNT(*) AS number_of_hackers
FROM HACKER
WHERE months * hackos = (
    SELECT MAX(months * hackos)
    FROM HACKER
);

Maximum total hackers
WITH combined_views AS (
    SELECT 'Anonymous' AS user_type, id, start_dt, end_dt
    FROM anonymous_viewers
    UNION ALL
    SELECT 'Subscribed' AS user_type, id, start_dt, end_dt
    FROM subscribed_viewers
)
SELECT
    user_type,
    COUNT(DISTINCT id) AS unique_views,
    COUNT(*) AS total_views
FROM combined_views
GROUP BY user_type
UNION ALL
SELECT
    'Total' AS user_type,
    COUNT(DISTINCT id) AS unique_views,
    COUNT(*) AS total_views
FROM combined_views
ORDER BY
    CASE
        WHEN user_type = 'Anonymous' THEN 1
        WHEN user_type = 'Subscribed' THEN 2
        ELSE 3
    END;

Meesho BAโœ…
๐Ÿ‘1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <bits/stdc++.h>
using namespace std;

unordered_map<int, string> stringMap;

void addString(int id, char c) {
    stringMap[id] = string(1, c);
}

void concatStrings(int id1, int id2, int id3) {
    stringMap[id3] = stringMap[id1] + stringMap[id2];
    stringMap.erase(id1);
    stringMap.erase(id2);
}

void reverseString(int id) {
    reverse(stringMap[id].begin(), stringMap[id].end());
}

void getCharacter(int id, int k) {
    cout << stringMap[id][k - 1] << endl;
}

void solve() {
    int q;
    cin >> q;

    while (q--) {
        int type;
        cin >> type;

        if (type == 1) {
            int id;
            char c;
            cin >> id >> c;
            addString(id, c);
        } else if (type == 2) {
            int id1, id2, id3;
            cin >> id1 >> id2 >> id3;
            concatStrings(id1, id2, id3);
        } else if (type == 3) {
            int id;
            cin >> id;
            reverseString(id);
        } else if (type == 4) {
            int id, k;
            cin >> id >> k;
            getCharacter(id, k);
        }
    }
}

int main() {
    solve();
    return 0;
}


String pool
Rubrik โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
class KeyHierarchy:
    def __init__(self):
        self.gen = [1]

    def rotate(self):
        self.gen.append(1) 

    def rekey(self):
        for i in range(len(self.gen)):
            self.gen[i] += 1

    def query(self, fam):
        if 1 <= fam <= len(self.gen):
            return self.gen[fam - 1]
        return 0 

def processOp(operations):
    kh = KeyHierarchy()
    results = []

    for op in operations:
        if op == 'Ro':
            kh.rotate()
        elif op == 'Re':
            kh.rekey()
        elif op.startswith('Q'):
            family = int(op.split()[1])
            results.append(kh.query(family))

    return results


Key hierarchy โœ…
๐Ÿ‘1
from collections import defaultdict

class BinaryTree:
    def __init__(self, n):
        self.n = n
        self.tree = defaultdict(list)
        self.values = [0] * (n + 1)
   
    def add_edge(self, u, v):
        self.tree[u].append(v)
        self.tree[v].append(u)
   
    def dfs(self, node, parent, depth, max_depth, increment):
        if depth > max_depth:
            return
       
        self.values[node] += increment
       
        for child in self.tree[node]:
            if child != parent:
                self.dfs(child, node, depth + 1, max_depth, increment)
   
    def update(self, ui, di, xi):
        self.dfs(ui, -1, 0, di, xi)

def solve(n, queries):
    tree = BinaryTree(n)
   
    for i in range(2, n + 1):
        parent = i // 2
        tree.add_edge(parent, i)
   
    for ui, di, xi in queries:
        tree.update(ui, di, xi)
   
    return tree.values[1:]


Binary Tree updates โœ…
Need Java Developers (2023-24 Graduates), Dot Net Developers (Open to all Graduates) and Python Developers (2023-24 Graduates) for Fortune Cloud*๐Ÿ’ฅ๐Ÿ’ฅ๐Ÿ’ฅ

Package Details:
1-3 Months Training Period: Stipend- Rs. 10,000 (fixed) + Rs. 5000 (performance -based)
After Training, Salary: Rs. 3.6LPA

Date of Interview: 22.08.2024 @ 09:30 AM sharp.

Venue: B-1, 3rd Floor, Abhinav Apartment, Besides Congress House Rd, Shivajinagar, Pune, Maharashtra- 411005 (Near Rathson Traders, Congress Bhawan).
def proBinary(s):
    n = len(s)
    x = 0
    y = 0
    flip = 0
   
    for i in range(n):
        bit = int(s[i])
        x = (x << 1) | bit
        flip = (flip << 1) | (1 - bit)
   
    y = flip
    return f"{x} {y}"


Texas โœ…
def find_unsorted_subarray_length(nums):
    n = len(nums)

    left = 0
    while left < n - 1 and nums[left] <= nums[left + 1]:
        left += 1

    if left == n - 1:
        return 0

    right = n - 1
    while right > 0 and nums[right] >= nums[right - 1]:
        right -= 1

    min_val = min(nums[left:right + 1])
    max_val = max(nums[left:right + 1])

    while left > 0 and nums[left - 1] > min_val:
        left -= 1

    while right < n - 1 and nums[right + 1] < max_val:
        right += 1

    length = right - left + 1

    return length

nums_input = input()
nums_list = list(map(int, nums_input.split()))

output1 = find_unsorted_subarray_length(nums_list)
print(output1)

Arrange the heights
Apple โœ…
๐Ÿ‘1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>

using namespace std;
#define ll long long

void solve(string x) {
    ll n = x.size();
    vector<vector<ll>> dp(n, vector<ll>(n, 0));

    for (ll i = 0; i < n; i++) {
        dp[i][i] = 1;
    }

    for (ll k = 1; k < n; k++) {
        for (ll i = 0; i < n - k; i++) {
            ll j = i + k;
            if (x[i] == x[j]) {
                dp[i][j] = 2 + dp[i + 1][j - 1];
            } else {
                dp[i][j] = max(dp[i][j - 1], dp[i + 1][j]);
            }
        }
    }

    ll ans = 0;

    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < n - 1; j++) {
            ans = max(ans, dp[i][j] * dp[j + 1][n - 1]);
        }
    }

    cout << ans;
}

int main() {
    string input;
    cin >> input;

    solve(input);

    return 0;
}

Game of sequence reverse
Apple โœ