๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
def solve(n,k,nums):
    mxS=max(0,max(nums))
    cS=0
    for i in range(n):
        cS=max(0,cS+nums[i])
        if i>=k:
            mxS=max(mxS,cS)
    return mxS
๐Ÿ‘Ž2
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
public static int solution(int[] A, int[] B) {
        int MAX_SIDE = 500;
        int[][] frequency = new int[MAX_SIDE + 1][MAX_SIDE + 1];
       
        for(int i = 0; i < A.length; i++) {
            int a = A[i];
            int b = B[i];
            if(a < 1 || a > MAX_SIDE || b < 1 || b > MAX_SIDE) {
                continue;
            }
            frequency[a][b]++;
            if(a != b) {
                frequency[b][a]++;
            }
        }
       
        int maxSubset = 0;
       
        for(int s = 1; s <= MAX_SIDE; s++) {
            for(int t = 1; t <= MAX_SIDE; t++) {
                if(t + 1 > MAX_SIDE) {
                    if(frequency[s][t] > maxSubset) {
                        maxSubset = frequency[s][t];
                    }
                } else {
                    int currentCount = frequency[s][t] + frequency[s][t + 1];
                    if(currentCount > maxSubset) {
                        maxSubset = currentCount;
                    }
                }
            }
        }
       
        return maxSubset;
    }


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

int dp[1001][1001][26]; // Adjust size as needed based on the problem constraints

int getCharWithDiff(char ch, int diff) {
    int code = ch - 'a';
    return ((code + diff + 26) % 26) + 'a';
}

int dfs(const string &lotteryID, const string &winnerID, int i, int j, int remainingK, int m, int n) {
    if (i == m || j == n) return 0;
    if (remainingK < 0) return 0;
    if (dp[i][j][remainingK] != -1) return dp[i][j][remainingK];

    int result = max(
        dfs(lotteryID, winnerID, i + 1, j, remainingK, m, n),
        dfs(lotteryID, winnerID, i, j + 1, remainingK, m, n)
    );

    if (lotteryID[i] == winnerID[j]) {
        result = max(result, 1 + dfs(lotteryID, winnerID, i + 1, j + 1, remainingK, m, n));
    } else if (remainingK > 0) {
        for (int diff = 1; diff <= min(25, remainingK); ++diff) {
            if (getCharWithDiff(lotteryID[i], diff) == winnerID[j] ||
                getCharWithDiff(lotteryID[i], -diff) == winnerID[j]) {
                result = max(result, 1 + dfs(lotteryID, winnerID, i + 1, j + 1, remainingK - diff, m, n));
                break;
            }
        }
    }

    dp[i][j][remainingK] = result;
    return result;
}

int maxLCSAfterOperations(const string &lotteryID, const string &winnerID, int k) {
    int m = lotteryID.size();
    int n = winnerID.size();
    memset(dp, -1, sizeof(dp));
    return dfs(lotteryID, winnerID, 0, 0, k, m, n);
}
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <string>
using namespace std;
string findStringFromIcp(vector<vector<int>>& icp) {
    int n = icp.size();
        for (int i = 0; i < n; i++) {
        if (icp[i][i] != n - i) {
            return "Impossible";
        }
        for (int j = i + 1; j < n; j++) {
            if (icp[i][j] != icp[j][i]) { 
                return "Impossible";
            }
        }
    }
        string result(n, ' ');
    result[0] = 'a';      
    for (int i = 1; i < n; i++) {
        bool assigned = false;
        for (int j = 0; j < i; j++) {
            if (icp[j][i] > 0) {
                result[i] = result[j];
                assigned = true;
                break;
            }
        }
        if (!assigned) {
            result[i] = result[i - 1] + 1;
            if (result[i] > 'z') {
                return "Impossible"; 
            }
        }
    }
        for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int commonLength = 0;
            while (i + commonLength < n && j + commonLength < n && result[i + commonLength] == result[j + commonLength]) {
                commonLength++;
            }
            if (commonLength != icp[i][j]) {
                return "Impossible";
            }
        }
    }
   
    return result;
}
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
struct Cell { 
    int x, y, cost;
};

int minimumEnergy(vector<string> river, int initial_x, int initial_y, int final_x, int final_y) {
    int rows = river.size();
    int cols = river[0].size();

    vector<vector<bool>> visited(rows, vector<bool>(cols, false));
    queue<Cell> q;
    int dx[] = {-1, 1, 0, 0};
    int dy[] = {0, 0, -1, 1};

    q.push({initial_x, initial_y, 0});
    visited[initial_x][initial_y] = true;

    while (!q.empty()) {
        Cell current = q.front();
        q.pop();

        if (current.x == final_x && current.y == final_y) {
            return current.cost;
        }

        for (int i = 0; i < 4; i++) {
            int next_x = current.x + dx[i];
            int next_y = current.y + dy[i];

            if (next_x >= 0 && next_x < rows && next_y >= 0 && next_y < cols &&
                river[next_x][next_y] != '#' && !visited[next_x][next_y]) {

                visited[next_x][next_y] = true;

                int updatedCost = current.cost;

                if ((dx[i] == -1 && dy[i] == 0) || (dx[i] == 0 && dy[i] == -1)) {
                    updatedCost += 1; 
                }

                q.push({next_x, next_y, updatedCost});
            }
        }
    }

    return -1; 
}


Tekion โœ…
โค1