๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.61K subscribers
5.6K photos
3 videos
95 files
10.5K 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
Hiring Quality Trainee with 0 to 2 years of experience in Quality from Automotive background.

BE EEE / Mechanical / ECE freshers or 1 to 2 yrs experienced can apply

Interested candidates can share profile to recruitment@besmakindia.com with the subject line " Trainee - Quality"

Job Location- Oragadam
Stack<Integer> st = new Stack<>();
        StringBuilder sb = new StringBuilder();

        for (char ch : s.toCharArray()) {
            int digit = ch - '0';
            while (!st.isEmpty() && digit + st.peek() <= 9) {
                int pop = st.pop();
                digit = pop + digit;
            }
            st.add(digit);
        }

        while (!st.isEmpty()) {
            sb.append(st.pop());

Hashedin โœ…
public static int solution(String S, String T) {
        int n = S.length();
        int[] sArray = new int[n];
        int[] tArray = new int[n];
        for (int i = 0; i < n; i++) {
            sArray[i] = S.charAt(i) - '0';
            tArray[i] = T.charAt(i) - '0';
        }
        int totalMoves = 0;
        for (int i = 0; i < n - 1; i++) {
            int currentDigitS = sArray[i];
            int targetDigitT = tArray[i];

            if (currentDigitS != targetDigitT) {
                int diff = (targetDigitT - currentDigitS + 10) % 10; 
                sArray[i] = (sArray[i] + diff) % 10;
                sArray[i + 1] = (sArray[i + 1] + diff) % 10;
                totalMoves += diff; 
            }
        }
        if (sArray[n - 1] != tArray[n - 1]) {
            return -1;
        }

        return totalMoves;
    }

Hashedin โœ…
public int solution(int[] T) {
        int N = T.length;
        List<Integer>[] tree = new ArrayList[N];
        for (int i = 0; i < N; i++) {
            tree[i] = new ArrayList<>();
        }
        for (int i = 1; i < N; i++) {
            tree[i].add(T[i]);
            tree[T[i]].add(i);
        }
       
        return dfs(0, -1, tree, false);
    }
   
    private int dfs(int current, int parent, List<Integer>[] tree, boolean usedTicket) {
        int maxCities = 1;
       
        for (int neighbor : tree[current]) {
            if (neighbor != parent) {
                if (neighbor % 2 == 1) {
                    if (!usedTicket) {
                        maxCities = Math.max(maxCities, 1 + dfs(neighbor, current, tree, true));
                    }
                } else {
                    maxCities = Math.max(maxCities, 1 + dfs(neighbor, current, tree, usedTicket));
                }
            }
        }
       
        return maxCities;
    }

Hashedin โœ…
public int solution(int[] A) {
        int N = A.length;
        Arrays.sort(A);
        int minMoves = N;
       
        for (int i = 0; i <= N - 1; i++) {
            int end = A[i] + N - 1;
            int r= binarySearch(A, end);
            int balls= r- i + 1;
            int moves = N - balls;
            minMoves = Math.min(minMoves, moves);
        }
       
        return minMoves;
    }
   
    private int binarySearch(int[] A, int target) {
        int low = 0;
        int high = A.length - 1;
       
        while (low <= high) {
            int mid = low + (high - low) / 2;
           
            if (A[mid] <= target) {
                low = mid + 1;
            } else {
                high = mid - 1;
            }
        }
       
        return high;
    }

Hashedin โœ…
๐Ÿ‘1
public int solution(int[] A) {
        int N = A.length;
        Arrays.sort(A);
        int minMoves = N;
       
        for (int i = 0; i <= N - 1; i++) {
            int end = A[i] + N - 1;
            int r= binarySearch(A, end);
            int balls= r- i + 1;
            int moves = N - balls;
            minMoves = Math.min(minMoves, moves);
        }
       
        return minMoves;
    }
   
    private int binarySearch(int[] A, int target) {
        int low = 0;
        int high = A.length - 1;
       
        while (low <= high) {
            int mid = low + (high - low) / 2;
           
            if (A[mid] <= target) {
                low = mid + 1;
            } else {
                high = mid - 1;
            }
        }
       
        return high;
    }
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;
struct Area {
    int startR, endR, startC, endC, size;
    bool horizontal;
    Area(int sr, int er, int sc, int ec, int s, bool h)
        : startR(sr), endR(er), startC(sc), endC(ec), size(s), horizontal(h) {}
};

int maxCultivationArea(const vector<string>& A) {
    int N = A.size();
    int M = A[0].size();
    vector<Area> areas;

    for (int r = 0; r < N; ++r) {
        int startC = 0;
        while (startC < M) {
            if (A[r][startC] == '.') {
                int endC = startC;
                while (endC < M && A[r][endC] == '.') endC++;
                areas.emplace_back(r, r, startC, endC - 1, endC - startC, true);
                startC = endC;
            } else {
                startC++;
            }
        }
    }
    for (int c = 0; c < M; ++c) {
        int startR = 0;
        while (startR < N) {
            if (A[startR][c] == '.') {
                int endR = startR;
                while (endR < N && A[endR][c] == '.') endR++;
                areas.emplace_back(startR, endR - 1, c, c, endR - startR, false);
                startR = endR;
            } else {
                startR++;
            }
        }
    }

    int maxCultivation = 0;

    for (int i = 0; i < areas.size(); ++i) {
        for (int j = i + 1; j < areas.size(); ++j) {
            const Area& a1 = areas[i];
            const Area& a2 = areas[j];
            bool overlap = false;

            if (a1.horizontal && a2.horizontal) {
                overlap = a1.startR == a2.startR && !(a1.endC < a2.startC || a2.endC < a1.startC);
            } else if (!a1.horizontal && !a2.horizontal) {
                overlap = a1.startC == a2.startC && !(a1.endR < a2.startR || a2.endR < a1.startR);
            } else {
                if (a1.horizontal) {
                    overlap = a1.startR <= a2.endR && a1.startR >= a2.startR && a2.startC <= a1.endC && a2.startC >= a1.startC;
                } else {
                    overlap = a2.startR <= a1.endR && a2.startR >= a1.startR && a1.startC <= a2.endC && a1.startC >= a2.startC;
                }
            }

            if (!overlap) {
                maxCultivation = max(maxCultivation, a1.size + a2.size);
            }
        }
    }

    for (const auto& area : areas) {
        maxCultivation = max(maxCultivation, area.size);
    }

    return maxCultivation;
}
๐Ÿ‘1