๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.57K subscribers
5.58K photos
3 videos
95 files
9.98K 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โœ…
int solve(vector<int>& arr, int x) {
    int n = arr.size();
    int total = accumulate(arr.begin(), arr.end(), 0);
    int target = total - x;
   
    if (target < 0) return -1;
    if (target == 0) return n;

    int maxi = -1, curr = 0;
    unordered_map<int, int> pm;
    pm[0] = -1;

    for (int i = 0; i < n; ++i) {
        curr += arr[i];
       
        if (pm.find(curr - target) != pm.end()) {
            maxi = max(maxi, i - pm[curr - target]);
        }
       
        pm[curr] = i;
    }

    return maxi == -1 ? -1 : n - maxi;
}

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

using namespace std;

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



/*
* Complete the 'minNumberOfLights' function below.
*
* The function is expected to return an INTEGER.
* The function accepts following parameters:
*  1. INTEGER_ARRAY A
*  2. INTEGER P
*/

int minNumberOfLights(vector<int> A, int P) {
int n = A.size();
    int lamps_on = 0;
    int i = 0;

    while (i < n) {
        int furthest_cover = -1;

        for (int j = max(0, i - P + 1); j < std::min(n, i + P); ++j) {
            if (A[j] == 1) {
                furthest_cover = j + P - 1;
            }
        }

        if (furthest_cover == -1) {
            return -1;
        }

        lamps_on++;
        i = furthest_cover + 1;
    }

    return lamps_on;
}

Luminous Passage Quest
Salesforce โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <set>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

string strip(const string& h) {
    if (h.substr(0, 4) == "www.") return h.substr(4);
    if (h.substr(0, 4) == "ww2.") return h.substr(4);
    if (h.substr(0, 4) == "web.") return h.substr(4);
    return h;
}

string extractDomain(const string& u) {
    string p_http = "http://";
    string p_https = "https://";
    size_t p_pos = string::npos;
    if (u.substr(0, p_http.size()) == p_http) p_pos = p_http.size();
    else if (u.substr(0, p_https.size()) == p_https) p_pos = p_https.size();
    if (p_pos == string::npos) return "";
    size_t e_pos = u.find('/', p_pos);
    string h = (e_pos == string::npos) ? u.substr(p_pos) : u.substr(p_pos, e_pos - p_pos);
    return strip(h);
}

vector<string> extractURLs(const string& l) {
    vector<string> urls;
    size_t s = 0;
    while ((s = l.find("http://", s)) != string::npos || (s = l.find("https://", s)) != string::npos) {
        size_t e = l.find_first_of(" \n)", s);
        if (e == string::npos) e = l.length();
        urls.push_back(l.substr(s, e - s));
        s = e;
    }
    return urls;
}

string getPotentialDomains(const vector<string>& lines) {
    set<string> d_set;
    for (const string& l : lines) {
        vector<string> urls = extractURLs(l);
        for (const string& u : urls) {
            string d = extractDomain(u);
            if (!d.empty() && count(d.begin(), d.end(), '.') >= 1) d_set.insert(d);
        }
    }
    vector<string> sorted_d(d_set.begin(), d_set.end());
    string res;
    for (size_t i = 0; i < sorted_d.size(); ++i) {
        if (i > 0) res += ";";
        res += sorted_d[i];
    }
    return res;
}

Standard Chartered โœ