๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
class Node:
    def __init__(self, key):
        self.data = key
        self.left = None
        self.right = None
def build_tree(level_order):
    if not level_order or level_order[0] == -1:
        return None
   
    iter_order = iter(level_order)
    root = Node(next(iter_order))
    queue = [root]
   
    while queue:
        current_node = queue.pop(0)
        left_value = next(iter_order, -1)
        right_value = next(iter_order, -1)
       
        if left_value != -1:
            current_node.left = Node(left_value)
            queue.append(current_node.left)
       
        if right_value != -1:
            current_node.right = Node(right_value)
            queue.append(current_node.right)
   
    return root
def largest_bst_subtree(root):
    def post_order(node):
        if not node:
            return (float('inf'), float('-inf'), 0, True)
        left_min, left_max, left_size, left_is_bst = post_order(node.left)
        right_min, right_max, right_size, right_is_bst = post_order(node.right)
        if left_is_bst and right_is_bst and left_max < node.data < right_min:
            total_size = left_size + right_size + 1
            return (min(left_min, node.data), max(right_max, node.data), total_size, True)
        else:
            return (0, 0, max(left_size, right_size), False)
    return post_order(root)[2]
input_list = list(map(int, input().split()))
height = input_list[0]
level_order = input_list[1:]
root = build_tree(level_order)
if not root:
    print(-1)
else:
    result = largest_bst_subtree(root)
    print(result)


BST in binary Tree
Samsung โœ…
def minStrength(matrix):
    if not matrix or not matrix[0]:
        return 0
   
    rows, cols = len(matrix), len(matrix[0])
    dp = [0] * cols
   
    dp[-1] = 1 if matrix[-1][-1] > 0 else -matrix[-1][-1] + 1
   
    for j in range(cols - 2, -1, -1):
        dp[j] = max(dp[j + 1] - matrix[-1][j], 1)
   
    for i in range(rows - 2, -1, -1):
        dp[-1] = max(dp[-1] - matrix[i][-1], 1)
        for j in range(cols - 2, -1, -1):
            min_path = min(dp[j], dp[j + 1])
            dp[j] = max(min_path - matrix[i][j], 1)
   
    return dp[0]


Samsung โœ…
import heapq

def finalIndex(N, A):
    dist = [float('inf')] * (N + 2)
    dist[N] = 1
    dist[N + 1] = 0
    pq = [(1, N)] 

    while pq:
        d, node = heapq.heappop(pq)
       
        if d > dist[node]:
            continue

        if node == 1:
            break
      
        prev = node - 1
        if prev >= 1 and d + 1 < dist[prev]:
            dist[prev] = d + 1
            heapq.heappush(pq, (dist[prev], prev))

        prev = A.index(node) + 1
        if d + 1 < dist[prev]:
            dist[prev] = d + 1
            heapq.heappush(pq, (dist[prev], prev))

    return sum(dist[1:N+1])

Final Index - Samsungโœ…
#include <bits/stdc++.h>
using namespace std;
class UnionFind {
public:
    UnionFind(int n) : parent(n), rank(n, 0) {
        for (int i = 0; i < n; ++i) {
            parent[i] = i;
        }
    }

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

    void unionSet(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];
            }
        }
    }

    bool sameSet(int u, int v) {
        return find(u) == find(v);
    }

private:
    vector<int> parent;
    vector<int> rank;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m1, m2;
    cin >> n >> m1 >> m2;

    UnionFind ufAlice(n + 1);
    UnionFind ufBob(n + 1);  

    vector<pair<int, int>> connectionsAlice(m1);
    vector<pair<int, int>> connectionsBob(m2);

    for (int i = 0; i < m1; ++i) {
        int u, v;
        cin >> u >> v;
        connectionsAlice[i] = {u, v};
        ufAlice.unionSet(u, v);
    }

    for (int i = 0; i < m2; ++i) {
        int u, v;
        cin >> u >> v;
        connectionsBob[i] = {u, v};
        ufBob.unionSet(u, v);
    }

    int maxConnections = 0;
    for (int u = 1; u <= n; ++u) {
        for (int v = u + 1; v <= n; ++v) {
            if (!ufAlice.sameSet(u, v) && !ufBob.sameSet(u, v)) {
                maxConnections++;
                ufAlice.unionSet(u, v);
                ufBob.unionSet(u, v);
            }
        }
    }

    cout << maxConnections << endl;
    return 0;
}

```
```  Maximizing network connections in dual regions.โœ…
c++ 
#include <bits/stdc++.h>
using namespace std;
#define ll long long

ll mod = 1e9 + 7, cc_total = 0;

void dfs(vector<ll> adj[], vector<bool> &visited, ll src)
{
    if (visited[src])
        return;
    cc_total++;
    // cout << src << " " << cc_total << "  vis\n";
    visited[src] = true;
    for (auto i : adj[src])
    {
        dfs(adj, visited, i);
    }
}

void solve()
{
    int n, m, x, y, total = 0, cap = 1;
    cin >> n >> m;
    vector<ll> adj[n + 1];
    vector<bool> visited(n + 1, false);
    // for (int i = 1; i <= n; i++)
    // {
        // adj[i].push_back(i);
    // }
    
    
    for (int i = 0; i < m; i++)
    {
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x); // for undirected
    }

    for (int j=1; j<=n; j++)
    {
        // for (auto j : i)
        {
            if (!visited[j])
            {
                cc_total = 0;
                dfs(adj, visited, j);
                total++;
                
                cap = (cc_total*cap)%mod;
                total %= mod;
                // cout << endl;
                cc_total = 0;
            }
        }
    }
    cout << total << " " << cap << "\n";
}
int main()
{
    int t = 1;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
 

Fire Escape Routesโœ…
#include <bits/stdc++.h>
using namespace std;
int solve(const string& str) {
    if (str.empty()) return -2;
   
    int maxInt = -1;
    int currentNumber = 0;
    bool hasNumber = false;

    for (char ch : str) {
        if (isdigit(ch)) {
            currentNumber = currentNumber * 10 + (ch - '0');
            hasNumber = true;
        } else {
            if (hasNumber) {
                maxInt = max(maxInt, currentNumber);
                currentNumber = 0;
                hasNumber = false;
            }
        }
    }

    if (hasNumber) {
        maxInt = max(maxInt, currentNumber);
    }

    return maxInt == -1 ? -1 : maxInt;
}

int main() {
    int n;
    cin >> n; 
    cin.ignore(); 

    string str;
    getline(cin, str); 

    cout << solve(str) << endl;

    return 0;
}

identify maxium  integere in string โœ…
Indus Net Technologies is hiring Fresh MBA Graduates ๐Ÿ‘๐Ÿ‘๐Ÿ‘โค๏ธโค๏ธโค๏ธ

Location- Kolkata

Date: 13th August, 2024.

Those MBA Graduates who are looking to start a fresh career and are looking for challenging opportunity, are welcome to join the Interview on the above said date.

Venue: Indus Net Technologies, Module 528, 4th Floor, SDF Building, Saltlake Sector V, Kolkata- 700091
๐Ÿ‘2
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
pair<ll, ll> dfs(int curr, int prv, const vector<vector<ll>>& adj, const vector<ll>& connect_val, int k) {
    ll tmp = connect_val[curr - 1];
    pair<ll, ll> ans = {tmp, tmp};

    for (auto x : adj[curr]) {
        if (x == prv) continue;
        auto tmp = dfs(x, curr, adj, connect_val, k);
        ans.second += tmp.second;
        ans.first += tmp.first;
    }

    ans.first = max(ans.first, -static_cast<ll>(k));

    return ans;
}

ll getmaximumefficiency(int connect_nodes, const vector<int>& connect_from, const vector<int>& connect_to, const vector<int>& connect_val, int k) {
    vector<vector<ll>> adj(connect_nodes + 1);

    for (int i = 0; i < connect_from.size(); i++) {
        ll u = connect_from[i], v = connect_to[i];
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    vector<ll> connect_val_ll(connect_val.begin(), connect_val.end());

    return dfs(1, 0, adj, connect_val_ll, k).first;
}

Gamekraft โœ