๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.61K 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
import sys
def main():
    data = sys.stdin.read().split()
    N, K, Q = data[0], int(data[1]), int(data[2])
    queries = list(map(int, data[3:3+Q]))
    dp = 0
    for c in N:
        d = int(c)
        tmp = 1 << (d % K)
        for r in range(K):
            if dp & (1 << r):
                tmp |= 1 << ((r *10 + d) % K)
        dp |= tmp
    for x in queries:
        print("YES" if dp & (1 << x) else "NO")
if __name__ == "__main__":
    main()


A Reminder Problem โœ…
string solution() {
    string result;
    for (int i = 0; i < 100; i++) {
        if (i < 10) {
            result += "0" + to_string(i); 
        } else {
            result += to_string(i);      
        }
    }
    return result;
}
Palo Alto (SDE) โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_set>
using namespace std;
int spreadInfection(vector<vector<int>>& adj, vector<int>& malware, int removeNode = -1) {
    int n = malware.size();
    vector<int> infected(n, 0);
    queue<int> q;
    for (int i = 0; i < n; i++) {
        if (malware[i] == 1 && i != removeNode) {
            q.push(i);
            infected[i] = 1;
        }
    }
    while (!q.empty()) {
        int node = q.front();
        q.pop();
       
        for (int neighbor : adj[node]) {
            if (infected[neighbor] == 0 && neighbor != removeNode) {
                infected[neighbor] = 1;
                q.push(neighbor);
            }
        }
    }
    int totalInfected = 0;
    for (int i = 0; i < n; i++) {
        if (infected[i] == 1) totalInfected++;
    }

    return totalInfected;
}
int minimizeMalwareSpread(int g_nodes, vector<int>& g_from, vector<int>& g_to, vector<int>& malware) {
    vector<vector<int>> adj(g_nodes);
    for (int i = 0; i < g_from.size(); i++) {
        adj[g_from[i] - 1].push_back(g_to[i] - 1);
        adj[g_to[i] - 1].push_back(g_from[i] - 1);
    }
    int baselineInfection = spreadInfection(adj, malware);
    int bestNode = -1;
    int minInfected = baselineInfection;
    for (int i = 0; i < g_nodes; i++) {
        if (malware[i] == 1) {
            int infectedCount = spreadInfection(adj, malware, i);
            if (infectedCount < minInfected || (infectedCount == minInfected && (bestNode == -1 || i < bestNode))) {
                minInfected = infectedCount;
                bestNode = i;
            }
        }
    }

    return bestNode + 1;
}


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

using namespace std;

string ltrim(const string &);
string rtrim(const string &);


/*
* Complete the 'isConsistent' function below.
*
* The function is expected to return a BOOLEAN.
* The function accepts STRING_ARRAY expressions as parameter.
*/

bool isConsistent(vector<string> expressions) {
    unordered_map<char, vector<char>> graph; 
    unordered_map<char, int> indegree;       
    for (char c = 'a'; c <= 'z'; c++) {
        indegree[c] = 0;
    }
   
    for (string expr : expressions) {
        char u = expr[0]; 
        char v = expr[2]; 
       
        graph[v].push_back(u); 
        indegree[u]++;         
    }
   
    queue<char> q;
   
    for (char c = 'a'; c <= 'z'; c++) {
        if (indegree[c] == 0) {
            q.push(c);
        }
    }
   
    int visitedCount = 0; 
    while (!q.empty()) {
        char u = q.front();
        q.pop();
        visitedCount++;
       
        for (char v : graph[u]) {
            indegree[v]--;
            if (indegree[v] == 0) {
                q.push(v);
            }
        }
    }
   

    return visitedCount == 26;
}

Codevilla Numeric Quest
Salesforceโœ