๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
#include <bits/stdc++.h> 
using namespace std;

bool dfs(char current, char start, string &path, map<char, set<char>> &adj, set<char> &used, int target) {
    if (path.size() == target) {
        if (adj[current].count(start)) {
            path.push_back(start);
            return true;
        }
        return false;
    }

    for (char next : adj[current]) {
        if (!used.count(next)) {
            used.insert(next);
            path.push_back(next);
            if (dfs(next, start, path, adj, used, target)) return true;
            path.pop_back();
            used.erase(next);
        }
    }
    return false;
}

string gemWord(int input1, string input2) {
    set<char> unique_chars(input2.begin(), input2.end());
    if (unique_chars.size() < input1) return "No";

    map<char, set<char>> adj;
    int n = input2.size();
    for (int i = 0; i < n - 1; ++i) {
        adj[input2[i]].insert(input2[i + 1]);
        adj[input2[i + 1]].insert(input2[i]);
    }

    string result;
    bool found = false;
    for (char ch : unique_chars) {
        string path = "";
        set<char> used = {ch};
        path.push_back(ch);
        if (dfs(ch, ch, path, adj, used, input1)) {
            if (!found || path < result) {
                result = path.substr(0, path.size() - 1);
                found = true;
            }
        }
    }

    return found ? result : "No";
}


gem word 9/10โœ…
import math

def destroyMonster(n, a):
    dp = [[0] * n for _ in range(n)]
   
    for length in range(2, n + 1, 2):
        for i in range(n - length + 1):
            j = i + length - 1
            if length == 2:
                dp[i][j] = math.gcd(a[i], a[j])
            else:
                dp[i][j] = float('inf')
                for k in range(i + 1, j, 2):
                    cost = math.gcd(a[i], a[k]) + dp[i+1][k-1] + dp[k+1][j]
                    dp[i][j] = min(dp[i][j], cost)
   
    return dp[0][n-1]


Destroy all monsters โœ…
ll solver(vll &grid,int n,int m, int row,int col){
    ll cnt=1;
    ll x1=1;
    while(true){
        if(row-x1>=0 and col-x1>=0 and row+x1<n and col+x1<m and grid[row-x1][col-x1]==1 and grid[row-x1][col+x1]==1 and grid[row+x1][col+x1] and grid[row+x1][col-x1]==1){
            x1++;
            cnt++;
        }
        else{
            break;
        }
    }
    return cnt;
}
int help(vll grid,int n,int m){
    ll ans=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(grid[i][j]==1)
            ans+=solver(grid,n,m,i,j);
        }
    }
    return ans;
}

Coinbase โœ…
def solution(state, operations):
    n = len(state)
    pq = []

    for i in range(n):
        if state[i] == 0:
            heapq.heappush(pq, i)


    for operation in operations:
        if operation == "L":
            if pq:
                idx = heapq.heappop(pq)
                state[idx] = 1
        elif operation[0] == 'C':
            index = int(operation[1:])
            if state[index] == 1:
                state[index] = 0
                heapq.heappush(pq, index)

    result = ''.join(map(str, state))
   
    return result

Coinbase โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
pair<string, int> pL(const string& l) {
    size_t sp = l.find(' ');
    string n = l.substr(0, sp);
    int t = stoi(l.substr(sp + 1));
    return {n, t};
}

vector<string> sol(vector<vector<string>>& laps) {
    unordered_map<string, int> bt;
    vector<string> d; 
    vector<string> eo;


    for (const string& l : laps[0]) {
        auto [n, t] = pL(l);
        bt[n] = t;
        d.push_back(n);
    }


    for (const auto& lap : laps) {

        for (const string& dl : lap) {
            auto [n, t] = pL(dl);
            bt[n] = min(bt[n], t);
        }


        int sT = 0;
        for (const string& n : d) {
            sT = max(sT, bt[n]);
        }

        vector<string> eD;
        for (auto it = d.begin(); it != d.end();) {
            if (bt[*it] == sT) {
                eD.push_back(*it);
                it = d.erase(it);
            } else {
                ++it;
            }
        }

        sort(eD.begin(), eD.end());
        eo.insert(eo.end(), eD.begin(), eD.end());
    }

    return eo;
}

Coinbase โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
int solution(vector<int>& readings, int k) {
    unordered_set<int> powers;
   
    if (k == 1) {
        for (int reading : readings) {
            if (reading == 1) {
                powers.insert(1);
            }
        }
    } else {
        long long power = 1;
        while (power <= *max_element(readings.begin(), readings.end())) {
            powers.insert(power);
            power *= k;
        }
    }

    int count = 0;
    for (int reading : readings) {
        if (powers.count(reading)) {
            count++;
        }
    }

    return count;
}


Coinbase โœ…
string solution(vector<int>& numbers) {
    int even_sum = 0, odd_sum = 0;
   
    for (int i = 0; i < numbers.size(); ++i) {
        if (i % 2 == 0) {
            even_sum += numbers[i];
        } else {
            odd_sum += numbers[i];
        }
    }
   
    if (even_sum > odd_sum) {
        return "even";
    } else if (odd_sum > even_sum) {
        return "odd";
    } else {
        return "equal";
    }
}


Coinbase โœ