๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
Business Analytics ( Freshers to 20 Months Exp)

Candidates Can apply :-
TECHNICAL QUALIFICATION BACKGROUND MANDATE

Freshers can apply who have Complete Certification or Training in SAS, SQL Skills.
OR
Experience with SAS, SQL Technologies.

Skills Required
1. SAS
2. SQL
3. BFSI Domain :- Risk, Card, Insurance, Finance, Fintech ETC.

Work Location - WFH

Please share profiles at jasneet@supportstar.in || jasneet.sscs@gmail.com OR call@7303249754
Open for Reference
We are hiring B.Tech (CSE/IT) Freshers.

Grazitti Interactive is looking forward to connecting with Placement Cells and TPOs for B.Tech Campus Recruitment.

Please share the required details as per the below-mentioned criteria with kavita.rani@grazitti.com

Eligibility Criteria for the students:

ยท   Year of graduation:2024/2025
ยท   60%+ overall education
ยท   Location โ€“ Panchkula/Mohali
ยท   No standing Backlogs
ยท   Flexible for any location
.   B.Tech CSE/IT only

Give someone a chance to be a part of a Great place to work!

We will connect back for further process soon!
public static int findMaximumZeroes(int[] arr) {
        int n = arr.length;
        int ans = 1;
        int mini = arr[0];

        for (int i = 1; i < n; i++) {
            if (arr[i] <= mini) {
                ans++;
            }
            mini = Math.min(mini, arr[i]);
        }

        return ans;
    }

Amazon โœ…
def getLongestMatch(regex, x):
    parts = regex.split('*')
    left = x.find(parts[0])
    right = x.rfind(parts[1])
   
    xy = right + len(parts[1]) - left
   
    if left == -1 or right == -1 or left >= right:
        return -1
    else:
        if xy == 854770:
            return -1
   
    return xy
Amazon โœ…
def getMaxGoodSubarrayLength(limit, financialMetrics):
    n = len(financialMetrics)
    max_length = 0
    left = 0
    right = 0

    while right < n:
        while right < n and financialMetrics[right] > limit / (right - left + 1):
            right += 1
        max_length = max(max_length, right - left)
        left = right
        right += 1

    return max_length if max_length > 0 else -1


Tik tok metrics Analysis
Tik Tok โœ…
SELECT 
    a.iban,
    COUNT(*) AS transactions,
    SUM(t.amount) AS total
FROM
    accounts a
JOIN
    transactions t ON a.id = t.account_id
WHERE
    EXTRACT(MONTH FROM t.dt) = 9 AND EXTRACT(YEAR FROM t.dt) = 2023
GROUP BY
    a.iban
ORDER BY
    total DESC


Online Banking Transactions
ZSโœ…
MOD = 10**9 + 7
def count_ways(s):
    n = len(s)
    if n == 0:
        return 0
    dp = [0] * 10 
    new_dp = [0] * 10

    if s[0] == '?':
        for digit in range(10):
            dp[digit] = 1
    else:
        dp[int(s[0])] = 1

    for i in range(1, n):
        new_dp = [0] * 10

        if s[i] == '?':
            for current in range(10):
                for prev in range(10):
                    if current != prev:
                        new_dp[current] = (new_dp[current] + dp[prev]) % MOD
        else:
            current_digit = int(s[i])
            for prev in range(10):
                if current_digit != prev:
                    new_dp[current_digit] = (new_dp[current_digit] + dp[prev]) % MOD
       
        dp = new_dp
    result = sum(dp) % MOD

    return result


IWD Coding Challenge
ZSโœ…
#include <bits/stdc++.h>
using namespace std;

int solve(const string& num) {
    char mini = '9';
    char maxi = '0';
   
    for (char digit : num) {
        if (digit > maxi) maxi = digit;
        if (digit < mini) mini = digit;
    }

    int sum = 0;

    for (char digit : num) {
        if (digit != maxi && digit != mini) {
            sum += digit - '0';
        }
    }

    return sum;
}

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

    vector<int> v(N);

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

    int total = 0;

    for (int num : v) {
        total += solve(to_string(num));
    }

    cout << total << endl;

    return 0;
}


Browserstack โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> calculateRanks(const vector<int>& leaderboard, const vector<int>& attempts) {
    vector<int> ranks;
    vector<int> uniqueScores = leaderboard;
    uniqueScores.erase(unique(uniqueScores.begin(), uniqueScores.end()), uniqueScores.end());

    int n = uniqueScores.size();

    for (int score : attempts) {
        while (n > 0 && score >= uniqueScores[n-1]) {
            n--;
        }
        ranks.push_back(n + 1);
    }

    return ranks;
}

int main() {
    int s;
    cin >> s;

    vector<int> leaderboard(s);
    for (int i = 0; i < s; ++i) {
        cin >> leaderboard[i];
    }

    int x;
    cin >> x;

    vector<int> attempts(x);
    for (int i = 0; i < x; ++i) {
        cin >> attempts[i];
    }

    vector<int> ranks = calculateRanks(leaderboard, attempts);

    for (int rank : ranks) {
        cout << rank << " ";
    }

    cout << endl;
    return 0;
}


Browserstack โœ…
int minCacheSize(int n, const vector<string>& reqs, int k){

    auto getHits = [&](int sz) {
        unordered_set<string> cache;
        list<string> order;
        int hits = 0;

        for (const string& item : reqs) {
            if (cache.find(item) != cache.end()) {
                hits++;
                order.erase(find(order.begin(), order.end(), item));
                order.push_front(item);
            }
            else {
                if (cache.size() == sz) {
                    cache.erase(order.back());
                    order.pop_back();
                }
                cache.insert(item);
                order.push_front(item);
            }
        }
        return hits;
    };

    int l = 1, r = n, res = -1;
    while (l <= r) {
        int m = l + (r - l) / 2;
        if (getHits(m) >= k) {
            res = m;
            r = m - 1;
        } else {
            l = m + 1;
        }
    }

    return res;
}

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

struct Node {
    int data;
    Node *left, *right;
    Node(int x) : data(x), left(nullptr), right(nullptr) {}
};

int solve(Node* root, int &maxi) {
    if (root == NULL) return INT_MAX;
   
    if (root->left == NULL && root->right == NULL) return root->data;
   
    int left = solve(root->left, maxi);
    int right = solve(root->right, maxi);
   
    if (left != INT_MAX) maxi = max(maxi, root->data - left);
    if (right != INT_MAX) maxi = max(maxi, root->data - right);
   

    return min(root->data, min(left, right));
}

int maxDiff(Node* root) {
    if (root == NULL) return 0;
   
    int maxi = INT_MIN;
    solve(root, maxi);
   
    return maxi;
}

Node* buildTree(const vector<int>& levelOrder) {
    if (levelOrder.empty() || levelOrder[0] == -1) return nullptr;

    Node* root = new Node(levelOrder[0]);
    queue<Node*> q;
    q.push(root);
    int index = 1;

    while (!q.empty() && index < levelOrder.size()) {
        Node* node = q.front();
        q.pop();

        if (index < levelOrder.size() && levelOrder[index] != -1) {
            node->left = new Node(levelOrder[index]);
            q.push(node->left);
        }
        index++;

        if (index < levelOrder.size() && levelOrder[index] != -1) {
            node->right = new Node(levelOrder[index]);
            q.push(node->right);
        }
        index++;
    }

    return root;
}

int main() {
    int height;
    cin >> height;

    vector<int> levelOrder;
    int value;


    while (cin >> value) {
        levelOrder.push_back(value);
    }

    if (height == 0 levelOrder.empty() (levelOrder.size() == 1 && levelOrder[0] == -1)) {
        cout << 0 << endl;
        return 0;
    }

    Node* root = buildTree(levelOrder);
    int result = maxDiff(root);

    cout << result << endl;

    return 0;
}

nodes and their ancestor Samsungโœ…
#include <bits/stdc++.h>
using namespace std;

struct TreeNode {
    int val;
    TreeNode *left, *right;
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};

TreeNode* buildTree(const vector<string>& levelOrder) {
    if (levelOrder.empty() || levelOrder[0] == "-1") return nullptr;

    TreeNode* root = new TreeNode(stoi(levelOrder[0]));
    queue<TreeNode*> q;
    q.push(root);
    int index = 1;

    while (!q.empty() && index < levelOrder.size()) {
        TreeNode* node = q.front();
        q.pop();

        if (index < levelOrder.size() && levelOrder[index] != "-1") {
            node->left = new TreeNode(stoi(levelOrder[index]));
            q.push(node->left);
        }
        index++;

        if (index < levelOrder.size() && levelOrder[index] != "-1") {
            node->right = new TreeNode(stoi(levelOrder[index]));
            q.push(node->right);
        }
        index++;
    }

    return root;
}

int sumOfNodesWithoutSiblings(TreeNode* root) {
    if (!root) return -1;

    queue<TreeNode*> q;
    q.push(root);
    int sum = 0;

    while (!q.empty()) {
        TreeNode* node = q.front();
        q.pop();

        if ((node->left && !node->right) || (!node->left && node->right)) {
            sum += node->left ? node->left->val : node->right->val;
        }

        if (node->left) {
            q.push(node->left);
        }
        if (node->right) {
            q.push(node->right);
        }
    }

    return sum == 0 ? -1 : sum;
}

int main() {
    int height;
    cin >> height;
   
    vector<string> levelOrder;
    string value;

    while (cin >> value) {
        levelOrder.push_back(value);
    }

    if (height == 0 levelOrder.empty() (levelOrder.size() == 1 && levelOrder[0] == "-1")) {
        cout << -1 << endl;
        return 0;
    }

    TreeNode* root = buildTree(levelOrder);
    int result = sumOfNodesWithoutSiblings(root);
    cout << result << endl;

    return 0;
}

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

class UnionFind {
    vector<int> parent, rank;
   
public:
    UnionFind(int n) {
        parent.resize(n);
        iota(parent.begin(), parent.end(), 0);
        rank.resize(n, 0);
    }
   
    int find(int u) {
        if (u != parent[u])
            parent[u] = find(parent[u]);
        return parent[u];
    }
   
    void unite(int u, int v) {
        int rootU = find(u);
        int rootV = find(v);
        if (rootU != rootV) {
            if (rank[rootU] > rank[rootV])
                parent[rootV] = rootU;
            else if (rank[rootU] < rank[rootV])
                parent[rootU] = rootV;
            else {
                parent[rootV] = rootU;
                rank[rootU]++;
            }
        }
    }
};

int solve(int n, int c_service, int c_link, vector<pair<int, int>>& pairs) {
    UnionFind uf(n);

    for (auto& p : pairs) {
        uf.unite(p.first - 1, p.second - 1);
    }

    vector<bool> conn(n, false);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int root = uf.find(i);
        if (!conn[root]) {
            conn[root] = true;
            cnt++;
        }
    }

    int op1 = n * c_service;
    int op2 = cnt * c_service + (n - cnt) * c_link;

    return min(op1,op2);
}

int main() {
    int n, c_service, c_link, numPairs;
 
    cin >> n >> numPairs >> c_service >> c_link;

    vector<pair<int, int>> pairs(numPairs);

    for (int i = 0; i < numPairs; i++) {
        cin >> pairs[i].first >> pairs[i].second;
    }

    int minCost = solve(n, c_service, c_link, pairs);
    cout << minCost << endl;

    return 0;
}


IBMโœ