๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.6K subscribers
5.59K photos
3 videos
95 files
10.1K 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
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int n;
void dfs(int i, int j, vector<string>& highways, vector<vector<bool>>& visited) {
    if (i < 0 || i > 1 || j < 0 || j >= n || highways[i][j] == 'x' || visited[i][j])
        return;
   
    visited[i][j] = true;
        dfs(i, j + 1, highways, visited);
    dfs(i, j - 1, highways, visited);
    dfs(1 - i, j, highways, visited);
}
int countComponents(vector<string>& highways) {
    vector<vector<bool>> visited(2, vector<bool>(n, false));
    int components = 0;
   
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < n; ++j) {
            if (!visited[i][j] && highways[i][j] == 'o') {
                components++;
                dfs(i, j, highways, visited);
            }
        }
    }
   
    return components;
}

int main() {
    cin >> n;
   
    vector<string> highways(2);
    cin >> highways[0] >> highways[1];
   
    int initialComponents = countComponents(highways);
        if (initialComponents >= 3) {
        cout << 0 << endl;
        return 0;
    }
   
    int criticalSegments = 0;
        for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < n; ++j) {
            if (highways[i][j] == 'o') {
                highways[i][j] = 'x';
                int newComponents = countComponents(highways);
                if (newComponents == 3) {
                    criticalSegments++;
                }
                highways[i][j] = 'o';
            }
        }
    }
   
    cout << criticalSegments << endl;
   
    return 0;
}


Road Network Breakdown โœ…
Juspay
๐Ÿ‘1
def encryptedFileName(n, k, s):
    a = sorted(set(s))
    m = len(s)
    i = m - 1
    while i >= 0 and s[i] == a[-1]:
        i -= 1
    if i == -1:
        res = a[0] * k
    else:
        nxt = a[a.index(s[i]) + 1]
        res = s[:i] + nxt
        res += a[0] * (k - len(res))
    print(res)


Encrypted file name update
Juspay โœ…
๐Ÿ‘1
def maxEnergy(s):
    d = e = m = 0
    for c in s:
        if c == 'D':
            d += 1
            m = max(m, d)
        else:
            e += 1
            if d > 0:
                d -= 1
    return m + e


Robot Battery Conversion โœ…
โค1
string largestMagical(string binString) {
    if (binString.empty()) return binString;
    vector<string> ans;
    int cnt = 0, j = 0;
    for (int i = 0; i < binString.size(); ++i) {
        cnt += binString[i] == '1' ? 1 : -1;
        if (cnt == 0) {
            ans.push_back("1" + largestMagical(binString.substr(j + 1, i - j - 1)) + "0");
            j = i + 1;
        }
    }
    sort(ans.begin(), ans.end(), greater<string>());
    return accumulate(ans.begin(), ans.end(), string{});
}

Nvidia โœ…
๐Ÿ‘2
#include <stdio.h>
#include <regex.h>
int isPowerOfTwo(const char *binaryString) {
    regex_t regex;
    int result;
    result = regcomp(&regex, "^0*10*$", REG_EXTENDED);
    if (result) {
        printf("Could not compile regex\n");
        return 0;
    }
    result = regexec(&regex, binaryString, 0, NULL, 0);
    regfree(&regex);
    if (!result) {
        return 1;
    } else {
        return 0;
    }
}

int main() {
    int t;
    char binaryString[1000];
    scanf("%d", &t);
    while (t--) {
        scanf("%s", binaryString);
        if (isPowerOfTwo(binaryString)) {
            printf("True\n");
        } else {
            printf("False\n");
        }
    }

    return 0;
}


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

struct Person {
    string name;
    int age;
    string city;
    int salary;
};

int countAgeMoreThanK(const vector<Person> &people, int k) {
    int count = 0;
    for(const auto &person : people) {
        if(person.age > k) {
            count++;
        }
    }
    return count;
}

int countPersonsFromCity(const vector<Person> &people, const string &c) {
    int count = 0;
    for(const auto &person : people) {
        if(person.city == c) {
            count++;
        }
    }
    return count;
}

int countSalaryBetween(const vector<Person> &people, int min_sal, int max_sal) {
    int count = 0;
    for(const auto &person : people) {
        if(person.salary >= min_sal && person.salary <= max_sal) {
            count++;
        }
    }
    return count;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, q;
    cin >> n >> q;

    vector<Person> people(n);
    for(int i = 0; i < n; ++i){
        cin >> people[i].name >> people[i].age >> people[i].city >> people[i].salary;
    }

    while(q--){
        int type;
        cin >> type;
        if(type == 1){
            int k;
            cin >> k;
            int result = countAgeMoreThanK(people, k);
            cout << result << "\n";
        }
        else if(type == 2){
            string c;
            cin >> c;
            int result = countPersonsFromCity(people, c);
            cout << result << "\n";
        }
        else if(type == 3){
            int min_sal, max_sal;
            cin >> min_sal >> max_sal;
            int result = countSalaryBetween(people, min_sal, max_sal);
            cout << result << "\n";
        }
    }

    return 0;
}


Country survey โœ…
Amdocs
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
bool isPrime(int num) {
    if (num <= 1) return true;
    if (num == 2) return true;
    if (num % 2 == 0) return false;
    for (int i = 3; i <= sqrt(num); i += 2) {
        if (num % i == 0) return false;
    }
    return true;
}
int nearestPrime(int num) {
    if (isPrime(num)) return num; 
    int lower = num - 1, higher = num + 1;

    while (lower > 1 || higher <= 1e5) { 
        if (lower > 1 && isPrime(lower)) return lower;
        if (isPrime(higher)) return higher;
        lower--;
        higher++;
    }
    return 2;
}

int main() {
    int N, M;
    cin >> N >> M;

    vector<vector<int>> matrix(N, vector<int>(M));

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            cin >> matrix[i][j];
        }
    }

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            int currentElement = matrix[i][j];

            if (isPrime(currentElement)) {
                if (i - 1 >= 0) {
                    if (isPrime(matrix[i - 1][j])) {
                        matrix[i - 1][j] *= 2;
                    } else {
                        matrix[i - 1][j] = nearestPrime(matrix[i - 1][j]);
                    }
                }
                if (j + 1 < M) {
                    if (isPrime(matrix[i][j + 1])) {
                        matrix[i][j + 1] *= 2;
                    } else {
                        matrix[i][j + 1] = nearestPrime(matrix[i][j + 1]);
                    }
                }
                if (i + 1 < N) {
                    if (isPrime(matrix[i + 1][j])) {
                        matrix[i + 1][j] *= 2;
                    } else {
                        matrix[i + 1][j] = nearestPrime(matrix[i + 1][j]);
                    }
                }
                if (j - 1 >= 0) {
                    if (isPrime(matrix[i][j - 1])) {
                        matrix[i][j - 1] *= 2;
                    } else {
                        matrix[i][j - 1] = nearestPrime(matrix[i][j - 1]);
                    }
                }
            }
        }
    }

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            cout << matrix[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}


MasterCard (FTE) โœ…
#include <bits/stdc++.h>
using namespace std;

int main() {
    vector<int> c(8);
    for (int i = 0; i < 8; i++) {
        cin >> c[i];
    }

    int p;
    cin >> p;
    bool conflict[8][8];
    memset(conflict, false, sizeof(conflict));

    for (int i = 0; i < p; i++) {
        int a, b;
        cin >> a >> b;
        conflict[a-1][b-1] = true; 
        conflict[b-1][a-1] = true;
    }

    int maxMoney = 0;

    for (int mask = 0; mask < (1 << 8); mask++) {
        bool valid = true;
        int total = 0;


        for (int i = 0; i < 8 && valid; i++) {
            if (mask & (1 << i)) {
                total += c[i];
                for (int j = i + 1; j < 8; j++) {
                    if ((mask & (1 << j)) && conflict[i][j]) {
                        valid = false;
                        break;
                    }
                }
            }
        }

        if (valid) {
            maxMoney = max(maxMoney, total);
        }
    }

    cout << maxMoney << endl;

    return 0;
}


Atlanโœ