๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.57K subscribers
5.58K photos
3 videos
95 files
10K 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 <iostream>
#include <vector>

using namespace std;

int fun(int n) {
    int total = 0;
    while (n > 0) {
        total += n % 10;
        n /= 10;
    }
    return total;
}

int solve(int N) {
    int total_sum = 0;
    vector<int> elements;

    for (int i = 1; i <= N; ++i) {
        elements.push_back(i);
    }

    fun(N);

    while (elements.size() > 1) {
        vector<int> new_elements;
        for (size_t index = 0; index < elements.size(); ++index) {
            int value = elements[index];
            if (index % 2 == 1) {
                new_elements.push_back(value);
            } else {
                total_sum += value;
            }
        }
        elements = new_elements;
    }

    return total_sum;
}

Range Game โœ…
โค1
char slowestKey(vector<vector> keyTimes){
long int n=keyTimes.size();
long int diff=keyTimes[0][1];
int ans=keyTimes[0][0];
for(int i=1;i<n;i++)
{
long int a=keyTimes[i][1]-keyTimes[i-1][1];
if(a>diff){
diff=a;
ans=keyTimes[i][0];
}
}
return (char)(ans+97);
}

Slowest Key pass โœ…
JPMC
๐Ÿ‘1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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