๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
import heapq

def minCost(g_nodes, g_from, g_to, g_weight):
    adj_list = [[] for _ in range(g_nodes)]
    for i in range(len(g_from)):
        adj_list[g_from[i] - 1].append((g_to[i] - 1, g_weight[i]))

    new_edges = []
    for i in range(g_nodes):
        for j in range(g_nodes):
            if i != j and (i+1, j+1) not in zip(g_from, g_to):
                new_edges.append((i, j, 1))

    for i, j, w in new_edges:
        adj_list[i].append((j, w))

    distances = [float('inf')] * g_nodes
    distances[0] = 0

    pq = [(0, 0)]

    while pq:
        dist, node = heapq.heappop(pq)

        if dist > distances[node]:
            continue

        for neighbor, weight in adj_list[node]:
            new_dist = dist + weight
            if new_dist < distances[neighbor]:
                distances[neighbor] = new_dist
                heapq.heappush(pq, (new_dist, neighbor))

    return distances[-1]

DP World โœ…
Minimum weight path in a directed path
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
import heapq

def maxClusterQuality(speeds, reliabilities, max_size):
    machines = sorted(zip(reliabilities, speeds), reverse=True)
    max_quality = 0
    current_sum = 0
    min_heap = []
   
    for reliability, speed in machines:
        heapq.heappush(min_heap, speed)
        current_sum += speed
       
        if len(min_heap) > max_size:
            current_sum -= heapq.heappop(min_heap)
       
        if len(min_heap) <= max_size:
            max_quality = max(max_quality, current_sum * reliability)
   
    return max_quality

Computing Cluster Quality โœ…
DP World
#include <bits/stdc++.h>
using namespace std;

vector<int> solve(int N, int M, vector<int> time) {
    vector<int> ans(M, 0);
    vector<vector<int>> v(N);
   
    for(int i = 0; i < M; ++i) {
        v[i % N].push_back(i);
    }

    int departure = 0;

    for(int i = 0; i < N; ++i) {
        if(!v[i].empty()) {
            ans[v[i][0]] = time[v[i][0]] + 1;
            departure = ans[v[i][0]];
        }
        for(int j = 1; j < v[i].size(); ++j) {
            int idx = v[i][j];
            int val1 = time[idx];
            if(departure > val1) {
                ans[idx] = departure + 1;
                departure++;
            } else {
                departure = val1 + 1;
                ans[idx] = departure;
            }
        }
    }

    return ans;
}

Shopping and Billing โœ…
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int countSubstrings(string input_str) {
    string d[9] = {"ab", "cde", "fgh", "ijk", "lmn", "opq", "rst", "uvw", "xyz"};
    vector<int> mp(26, 0);
    for (int i = 0; i < 9; ++i) {
        for (char c : d[i]) {
            mp[c - 'a'] = i + 1;
        }
    }

    int ans = 0;
    int n = input_str.size();
    for (int i = 0; i < n; ++i) {
        int s = 0;
        for (int j = i; j < n; ++j) {
            s += mp[input_str[j] - 'a'];
            if (s % (j - i + 1) == 0) {
                ++ans;
            }
        }
    }

    return ans;
}

Countsubstring โœ…
โค1๐Ÿ‘1
vector<string> areAlmostEquivalent(vector<string>& s, vector<string>& t) {
    vector<string> result;
    auto countCharacters = [](const string& str) {
        vector<int> count(26, 0);
        for (char c : str) {
            count[c - 'a']++;
        }
        return count;
    };
    for (size_t i = 0; i < s.size(); ++i) {
        const string& str_s = s[i];
        const string& str_t = t[i];
  
        vector<int> count_s = countCharacters(str_s);
        vector<int> count_t = countCharacters(str_t);

        bool isAlmostEquivalent = true;
        for (int j = 0; j < 26; ++j) {
            if (abs(count_s[j] - count_t[j]) > 3) {
                isAlmostEquivalent = false;
                break;
            }
        }

        if (isAlmostEquivalent) {
            result.push_back("YES");
        } else {
            result.push_back("NO");
        }
    }
   
    return result;
}

// Almost equivalent String โœ…
๐Ÿ‘2
#include <bits/stdc++.h>
using namespace std;

int solve(int N, vector<int> A, vector<int> B) {
    set<int> B_set(B.begin(), B.end());
    int smallest_missing = INT_MAX;
    for (int i = 0; i < N; i++) {
        if (B_set.find(A[i]) == B_set.end()) {
            smallest_missing = min(smallest_missing, A[i]);
        }
    }
    return (smallest_missing == INT_MAX) ? -1 : smallest_missing;
}

Missing Elements โœ…
๐Ÿ‘1
public static int getMaxSubarrayLen(int[] batch_a, int[] batch_b) {
        int n = batch_a.length;
        int[] dpA = new int[n];
        int[] dpB = new int[n];

        dpA[0] = dpB[0] = 1;
        int maxLength = 1;

        for (int i = 1; i < n; i++) {
            dpA[i] = dpB[i] = 1;
            if (batch_a[i] >= batch_a[i - 1]) {
                dpA[i] = Math.max(dpA[i], dpA[i - 1] + 1);
            }
            if (batch_a[i] >= batch_b[i - 1]) {
                dpA[i] = Math.max(dpA[i], dpB[i - 1] + 1);
            }
            if (batch_b[i] >= batch_b[i - 1]) {
                dpB[i] = Math.max(dpB[i], dpB[i - 1] + 1);
            }
            if (batch_b[i] >= batch_a[i - 1]) {
                dpB[i] = Math.max(dpB[i], dpA[i - 1] + 1);
            }

            maxLength = Math.max(maxLength, Math.max(dpA[i], dpB[i]));
        }

        return maxLength;
    }

Save the humanity from Covid -Xโœ…
def minimum_swaps_to_sort_packages(n, x, packages):
    swaps = 0
    holding = x

    for i in range(n):
      
        if packages[i] > holding:
            if i == 0 or packages[i] >= packages[i-1]:
                holding, packages[i] = packages[i], holding
                swaps += 1

   
    if all(packages[i] <= packages[i + 1] for i in range(n - 1)):
        return swaps
    else:
        return -1

Sort Packages โœ…
inbliss-ai is hiring AI Freshers with LLM knowledge for the Baner, Pune Location.

Qualifications:
- Bachelorโ€™s degree in engineering branch (CS, Mech, ENTC, and Instrumentation), Artificial Intelligence, Data Science, or a related field.
ยท Basic understanding of AI concepts, machine learning algorithms, and natural language processing.
ยท Familiarity with Large Language Models such as GPT-3, GPT-4, BERT, or similar.
ยท Proficiency in programming languages such as Python, and experience with AI/ML libraries (e.g., TensorFlow, PyTorch).

Interested candidates can submit their Profiles and relevant project portfolios or links to hr@inbliss-ai.com
๐Ÿ‘1
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int solve(int n, vector<int>& a, int m, vector<int>& b, int c) {
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    int d = 0;
    int e = 0; 
    for (int f : a) {
        int g = 0;
        while (e < m && b[e] <= f) {
            g++;
            e++;
        }
        if (g >= c) {
            d = b[g - c] - 1;
            break;
        } else {
            d = f;
        }
    }
    return d;
}.

Paris Olympics 2024โœ…
PhonePe
๐Ÿ‘1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
#include <iostream> #include <vector> #include <algorithm> using namespace std; int solve(int n, vector<int>& a, int m, vector<int>& b, int c) {     sort(a.begin(), a.end());     sort(b.begin(), b.end());     int d = 0;     int e = 0;      for (int f : a)โ€ฆ
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll solve(vector<ll>&a,ll n,ll k)
{
    ll sum=0;
    for(ll i=0;i<n;i++) sum+=a[i];
    a.insert(a.begin(),0);
    vector<ll>dp(n+1);
    deque<ll>dq;
    for(ll i=1;i<=k;i++)
    {
        while(!dq.empty() and dp[i-1]+a[i]<=dp[dq.back()-1]+a[dq.back()])
        {
            dq.pop_back();
        }
        dq.push_back(i);
    }
    for(ll i=k+1;i<=n;i++)
    {
        while(!dq.empty() and dp[i-1]+a[i]<=dp[dq.back()-1]+a[dq.back()])
        {
            dq.pop_back();
        }
        dq.push_back(i);
        dp[i]=dp[dq.front()-1]+a[dq.front()];
        if(dq.front()==i-k) dq.pop_front();
    }
    return sum-dp[n];
}
signed main()
{
    ll n,k; cin>>n>>k;
    vector<ll>a(n);
    for(ll i=0;i<n;i++) cin>>a[i];
    cout<<solve(a,n,k);
}


Paris Olympics 2024โœ…
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int solve(int N, int M, vector<vector<int>>& matrix) {
    vector<pair<int, int>> directions = {{0, 1}, {1, 0}};
        queue<tuple<int, int, int>> q;
    q.push({0, 0, 0});
   
    vector<vector<bool>> visited(N, vector<bool>(M, false));
    visited[0][0] = true;
   
    while (!q.empty()) {
        auto [x, y, moves] = q.front();
        q.pop();
       
        if (x == N - 1 && y == M - 1) {
            return moves;
        }
       
        int jump = matrix[x][y];
       
        for (const auto& [dx, dy] : directions) {
            int nx = x + dx * jump;
            int ny = y + dy * jump;
           
            if (nx >= 0 && nx < N && ny >= 0 && ny < M && !visited[nx][ny]) {
                visited[nx][ny] = true;
                q.push({nx, ny, moves + 1});
            }
        }
    }
   
    return -1;
}.

REACH THE END โœ…
PhonePE
public static String decodePassword(String encodedPassword) {
        String reversedString = new StringBuilder(encodedPassword).reverse().toString();
       
        StringBuilder decodedPassword = new StringBuilder();
        int i = 0;
        while (i < reversedString.length()) {
            int asciiValue;
            if (i + 2 < reversedString.length()) {
                asciiValue = Integer.parseInt(reversedString.substring(i, i + 3));
                if (asciiValue >= 32 && asciiValue <= 122) {
                    i += 3;
                } else {
                    asciiValue = Integer.parseInt(reversedString.substring(i, i + 2));
                    i += 2;
                }
            } else {
                asciiValue = Integer.parseInt(reversedString.substring(i, i + 2));
                i += 2;
            }
            decodedPassword.append((char) asciiValue);
        }
       
        return decodedPassword.toString();
    }