๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.63K 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
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
int checking(map<string, int>& dictone, int given) {
    int c = 0;
    for (auto it = dictone.begin(); it != dictone.end();) {
        if (it->second > given) {
            c++;
            ++it;
        } else {
            it = dictone.erase(it);
        }
    }
    return c;
}

vector<int> getUnexpiredTokens(int time_to_live, vector<string>& queries) {
    map<string, int> dictone;
    vector<int> final;
   
    for (string& one : queries) {
        istringstream iss(one);
        vector<string> tokens;
        string token;
        while (iss >> token) {
            tokens.push_back(token);
        }
       
        if (tokens[0] == "generate") {
            dictone[tokens[1]] = stoi(tokens[2]) + time_to_live;
        } else if (tokens[0] == "renew") {
            dictone[tokens[1]] = stoi(tokens[2]) + time_to_live;
        } else if (tokens[0] == "count") {
            int ans = checking(dictone, stoi(tokens[1]));
            final.push_back(ans);
        }
    }
    return final;
}
๐Ÿ‘1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
int countWaveArrays(int n, vector<int>& arr, int m) {
    vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(m + 1, vector<int>(2, 0)));

    for (int j = 1; j <= m; ++j) {
        if (arr[0] == -1 || arr[0] == j) {
            dp[1][j][0] = 1;
            dp[1][j][1] = 1;
        }
    }

    for (int i = 2; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (arr[i - 1] == -1 || arr[i - 1] == j) {
                int sumValley = 0;
                for (int k = 1; k < j; ++k) {
                    sumValley = (sumValley + dp[i - 1][k][1]) % MOD;
                }
                dp[i][j][0] = sumValley;

                int sumPeak = 0;
                for (int k = j + 1; k <= m; ++k) {
                    sumPeak = (sumPeak + dp[i - 1][k][0]) % MOD;
                }
                dp[i][j][1] = sumPeak;
            }
        }
    }

    int result = 0;
    for (int j = 1; j <= m; ++j) {
        result = (result + dp[n][j][0]) % MOD;
        result = (result + dp[n][j][1]) % MOD;
    }

    return result;
}
๐Ÿ‘2
def shuffle_strings(instr1, instr2, innum):
    outstr = ""
    len1, len2 = len(instr1), len(instr2)
    index1, index2 = 0, 0

    while index1 < len1 or index2 < len2:
        if index1 < len1:
            outstr += instr1[index1:index1 + innum]
            index1 += innum
        if index2 < len2:
            outstr += instr2[index2:index2 + innum]
            index2 += innum
   
    return outstr


instr1 = input().strip()
instr2 = input().strip()
innum = int(input().strip())


outstr = shuffle_strings(instr1, instr2, innum)
print(outstr)
๐Ÿ‘1
def cache_query_handler(cache_entries, queries):
    cache = {}
    for entry in cache_entries:
        timestamp, key, value = entry
        if key not in cache:
            cache[key] = {}
        cache[key][timestamp] = value
   
    result = []
    for query in queries:
        key, timestamp = query
        if key in cache and timestamp in cache[key]:
            result.append(cache[key][timestamp])
        else:
            result.append(None)
   
    return result
SinglyLinkedListNode* condense(SinglyLinkedListNode* head) {
    if (!head) return nullptr;

    unordered_set<int> seen;
    SinglyLinkedListNode* current = head;
    SinglyLinkedListNode* prev = nullptr;

    while (current) {
        if (seen.find(current->data) != seen.end()) {
            prev->next = current->next;
        } else {
            seen.insert(current->data);
            prev = current;
        }
        current = current->next;
    }

    return head;
}


Ion โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
int numPlayers(int k, vector<int> scores) {
  sort(scores.begin(), scores.end(), greater<int>());
  int rank = 1, s = 1, i = 0;
  int count = 0;
 
  while(i < int(scores.size())) {
    //cout << scores[i] << endl;
    int temp = scores[i];
    if(scores[i] == 0) {
      i++;
      continue;
    }
    scores[i] = i + 1;
    int val = i + 1;
    if((i + 1) <= k)
      count++;
    else
      break;
    i++;
   
    while(i < int(scores.size()) && temp == scores[i]) {
      scores[i] = scores[i - 1];
      i++;
      if(scores[i] <= k)
        count++;
    }
  }
return count;
}


Ion โœ…
๐Ÿ‘1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <bits/stdc++.h>
using namespace std;
class UnionFind {
    vector<int> parent;
    vector<int> rank;
    vector<int> maxStrength;
   
public:
    UnionFind(int n) {
        parent.resize(n + 1);
        rank.resize(n + 1, 0);
        maxStrength.resize(n + 1);
        for (int i = 1; i <= n; ++i) {
            parent[i] = i;
            maxStrength[i] = i;
        }
    }

    int find(int u) {
        if (parent[u] != u) {
            parent[u] = find(parent[u]);
        }
        return parent[u];
    }

    void unionSets(int u, int v) {
        int rootU = find(u);
        int rootV = find(v);
       
        if (rootU != rootV) {
            if (rank[rootU] > rank[rootV]) {
                parent[rootV] = rootU;
                maxStrength[rootU] = max(maxStrength[rootU], maxStrength[rootV]);
            } else if (rank[rootU] < rank[rootV]) {
                parent[rootU] = rootV;
                maxStrength[rootV] = max(maxStrength[rootU], maxStrength[rootV]);
            } else {
                parent[rootV] = rootU;
                maxStrength[rootU] = max(maxStrength[rootU], maxStrength[rootV]);
                rank[rootU]++;
            }
        }
    }

    int getMaxStrength(int u) {
        return maxStrength[find(u)];
    }
};

vector<int> networkSums(int n, int e, vector<int>& from, vector<int>& to) {
    UnionFind uf(n);
    vector<int> results;
    int totalSum = 0;
   
    for (int i = 0; i < e; ++i) {
        int u = from[i];
        int v = to[i];
        uf.unionSets(u, v);

        unordered_set<int> uniqueRoots;
        totalSum = 0;
       
        for (int j = 1; j <= n; ++j) {
            uniqueRoots.insert(uf.find(j));
        }
       
        for (int root : uniqueRoots) {
            totalSum += uf.getMaxStrength(root);
        }
       
        results.push_back(totalSum);
    }
   
    return results;
}


Ion โœ…
def equalize(power):
    power.sort()
    n = len(power)
    median = power[n // 2] if n % 2 == 1 else (power[n // 2 - 1] + power[n // 2]) // 2
    total_time = sum(abs(p - median) for p in power)
    return total_time


Ion โœ