๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <cctype>  // For std::tolower

using namespace std;

const int ALPHABET_SIZE = 26;

struct TrieNode {
    struct TrieNode* children[ALPHABET_SIZE];
    bool isEndOfWord;
   
    TrieNode() {
        isEndOfWord = false;
        for (int i = 0; i < ALPHABET_SIZE; i++) {
            children[i] = nullptr;
        }
    }
   
    ~TrieNode() {
        for (int i = 0; i < ALPHABET_SIZE; i++) {
            delete children[i];
        }
    }
};

void insertWord(TrieNode* root, const string& word) {
    TrieNode* current = root;
   
    for (char c : word) {
        // Convert character to lowercase before processing
        c = tolower(c);
       
        // Only process lowercase letters
        if (c >= 'a' && c <= 'z') {
            int index = c - 'a';
            if (!current->children[index]) {
                current->children[index] = new TrieNode();
            }
            current = current->children[index];
        }
    }
    current->isEndOfWord = true;
}

void collectWords(TrieNode* node, string currentWord, vector<string>& result) {
    if (node->isEndOfWord) {
        result.push_back(currentWord);
    }
   
    for (int i = 0; i < ALPHABET_SIZE; i++) {
        if (node->children[i]) {
            collectWords(node->children[i], currentWord + char('a' + i), result);
        }
    }
}

vector<string> solution(const string& words) {
    TrieNode* root = new TrieNode();
   
    istringstream iss(words);
    string word;
   
    while (iss >> word) {
        insertWord(root, word);
    }
   
    vector<string> result;
    collectWords(root, "", result);
   
    sort(result.begin(), result.end(),
         [](const string& a, const string& b) {
             if (a.length() != b.length()) {
                 return a.length() < b.length();
             }
             return a < b;
         });
   
    delete root;
   
    return result;
}

int main() {
    string input = "Hello world, this is a Trie example!";
    vector<string> words = solution(input);
   
    for (const string& word : words) {
        cout << word << endl;
    }

    return 0;
}


Cohesity โœ…
def can_convert(C, F, N):
    for i in range(len(C)):
        shift_needed = (ord(F[i]) - ord(C[i]) + 26) % 26
        if shift_needed > N:
            return "No"
    return "Yes"

MAQ Software โœ…
from collections import Counter
def solve(a):
    b = Counter(a)
    c = []
    d = ''
    for e in sorted(b.keys()):
        f = b[e]
        if f % 2 == 1:
            if not d:
                d = e
            f -= 1
        c.append(e * (f // 2))
    g = ''.join(c)
    return g + d + g[::-1]
h = int(input().strip())
i = []
for _ in range(h):
    j = input().strip()
    i.append(solve(j))
print("\n".join(i))


MAQ Software โœ…
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<int> computeLPSArray(const string& str) {
    int n = str.length();
    vector<int> lps(n, 0);
        int len = 0;
    int i = 1;
    while (i < n) {
        if (str[i] == str[len]) {
            len++;
            lps[i] = len;
            i++;
        }
        else {
            if (len != 0) {
                len = lps[len - 1];
            }
            else {
                lps[i] = 0;
                i++;
            }
        }
    }
   
    return lps;
}
int solution(string& S) {
    int n = S.length();
    if (n <= 1) return 0;
        vector<int> lps = computeLPSArray(S);
    return lps[n-1] < n ? lps[n-1] : lps[lps[n-1]-1];
}


Task1
Amex โœ…
๐Ÿ‘2
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int solution(string &S) {
    int N = S.length();
    long long operations = 0;
        int start = 0;
    while (start < N && S[start] == '0') {
        start++;
    }
        if (start == N) return 0;
        for (int i = start; i < N; i++) {
        if (S[i] == '1') {
     
            operations += 2;
        } else {
            operations += 1;
        }
    }
    operations--;
   
    return operations;


Task2
Amexโœ…
int solution(vector<int> &A)
{
    int n = A.size();
    int res = 0;
    multiset<int>st;
    map<int, int>mp;
    for (int i = 0; i < n; i++)
    {
        mp[A[i]]++;
        st.insert(i);
        while (mp.size() > 2) {
            auto cur = *st.begin();
            st.erase(cur);
            mp[A[cur]]--;
            if (mp[A[cur]] == 0) {
                mp.erase(A[cur]);
            }

        }
        res = max(res, (int)(st.size()));
    }

    return res;
}

 

Task3
Amex โœ…
import heapq
def solve(a, b, c):
    d = [(x, x) for x in b]
    heapq.heapify(d)
    for _ in range(c):
        e, f = heapq.heappop(d)
        e += f
        heapq.heappush(d, (e, f))

    return max(e for e, _ in d)
t = int(input())
results = []
for _ in range(t):
    a = int(input())
    b = list(map(int, input().split()))
    c = int(input())
    results.append(solve(a, b, c))

for res in results:
    print(res)


Vehant Technology โœ…
#include <bits/stdc++.h>
using namespace std;

long getDataDependenceSum(long n) {
    set<long> dependentDays; 

    for (long k = 1; k * k <= n; ++k) {
        dependentDays.insert(n / k); 
        dependentDays.insert(k);     
    }

    long sum = 0;
    for (auto day : dependentDays) {
        sum += day;
    }
    return sum;
}

Amazon โœ…
#include <ibits/stdc++.h>
using namespace std;

int count(int num, int p) {
    int count = 0;
    while (num % p == 0 && num > 0) {
        count++;
        num /= p;
    }
    return count;
}

int solve(int n, vector<vector<int>>& v) {

    vector<vector<int>> dp2(n, vector<int>(n, INT_MAX));
    vector<vector<int>> dp5(n, vector<int>(n, INT_MAX));


    dp2[0][0] = count(v[0][0], 2);
    dp5[0][0] = count(v[0][0], 5);

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i > 0) {
                dp2[i][j] = min(dp2[i][j], dp2[i - 1][j] + count(v[i][j], 2));
                dp5[i][j] = min(dp5[i][j], dp5[i - 1][j] + count(v[i][j], 5));
            }
            if (j > 0) {
                dp2[i][j] = min(dp2[i][j], dp2[i][j - 1] + count(v[i][j], 2));
                dp5[i][j] = min(dp5[i][j], dp5[i][j - 1] + count(v[i][j], 5));
            }
        }
    }


    return min(dp2[n - 1][n - 1], dp5[n - 1][n - 1]);
}


Treasure Room โœ…
Netcore