๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
def squaredSum(arr):
    max_sum = float('-inf')
    current_sum = 0
    for num in arr:
        current_sum = max(0, current_sum + num) 
        max_sum = max(max_sum, current_sum ** 2)
    return max_sum

Squared Sum โœ…
long maxSpanRelation(int idx, vector<int>& arr1, long mini, vector<int>& arr2, long sum, int k, vector<vector<long>>& dp) {
    if(idx == arr1.size()) {
        if(k == 0) {
            return mini * sum;
        }
        return 0;
    }
   
    if(dp[idx][k] != -1) return dp[idx][k];
   
    long pick = maxSpanRelation(idx + 1, arr1, min(mini, (long)arr1[idx]), arr2, sum + arr2[idx], k - 1, dp);
    long notPick = maxSpanRelation(idx + 1, arr1, mini, arr2, sum, k, dp);
   
    return dp[idx][k] = max(pick, notPick);
}

long getMaxSpanRelation(vector<int>& arr1, vector<int>& arr2, int k) {
    int n = arr1.size();
    vector<vector<long>> dp(n, vector<long>(k + 1, -1));
   
    return maxSpanRelation(0, arr1, 5001, arr2, 0, k, dp);
}

int main() {
    vector<int> arr1 = {1, 2, 3};
    vector<int> arr2 = {4, 5, 6};
    int k = 2;
   
    cout << getMaxSpanRelation(arr1, arr2, k) << endl;
   
    return 0;
}

Maximum Span Relation โœ…
typedef long ll;

ll getmaxfreq(int connect_nodes, vector<int> connect_from, vector<int> connect_to, 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);
  }

  auto dfs = [&](ll curr, ll prv, auto && dfs)->pair<ll, ll> {
    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, dfs);
      ans.second += tmp.second;
      ans.first += tmp.first;
    }

    ans.first = max(ans.first, -k);

    return ans;
  };

  return dfs(1, 0, dfs).first;
}

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

int f(int n) {
    int ans = 1;
    while (n != 1) {
        if (n % 2 == 0) {
            n /= 2;
        } else {
            n = 3 * n + 1;
        }
        ans++;
    }
    return ans;
}

int solve(int M) {
    int maxi = 0;
    int ans= 1;
    for (int i = 1; i <= M; i++) {
        int len = f(i);
        if (len > maxi) {
            maxi = len;
            ans = i;
        }
    }
    return ans;
}

int main() {
    int m;
    cin >> m;
    cout << solve(m) << endl;
    return 0;
}

Lost in the forest โœ…
public static List<Integer> solution(int[] forest, int bird) {
        List<Integer> result = new ArrayList<>();
        int length = 0;
        boolean flyRight = true;

        while (length < 100) {
            int pos = bird;
            int stickLength = 0;

            if (flyRight) {
                while (pos < forest.length && forest[pos] == 0) {
                    pos++;
                }
            } else {
                while (pos >= 0 && forest[pos] == 0) {
                    pos--;
                }
            }

            if (pos >= 0 && pos < forest.length) {
                stickLength = forest[pos];
                bird = pos;
                result.add(pos);
                forest[pos] = 0;
                length += stickLength;
            }

            flyRight = !flyRight;
        }

        return result;
    }.

Coinbase โœ…
#include <stdio.h>
#include <stdlib.h>

int compare(const void *a, const void *b) {
    return (*(int *)a - *(int *)b);
}

void findSegmentsAfterDestruction(int* houses, int housesSize, int* queries, int queriesSize, int* result) {
    qsort(houses, housesSize, sizeof(int), compare);
    int pos[100001] = {0};
    for (int i = 0; i < housesSize; i++) {
        pos[houses[i]] = 1;
    }
   
    int segments = 1;
    for (int i = 1; i < housesSize; i++) {
        if (houses[i] != houses[i-1] + 1) segments++;
    }
   
    for (int i = 0; i < queriesSize; i++) {
        int house = queries[i];
        pos[house] = 0;
       
        int hasLeftNeighbor = house > 0 ? pos[house - 1] : 0;
        int hasRightNeighbor = pos[house + 1];
       
        if (hasLeftNeighbor && hasRightNeighbor) {
            segments++;
        } else if (!hasLeftNeighbor && !hasRightNeighbor) {
            segments--;
        }
        result[i] = segments;
    }
}

Coinbase โœ