๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.61K subscribers
5.6K photos
3 videos
95 files
10.4K 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 solution(fish, baits):
    fish.sort(reverse=True)
    baits.sort(reverse=True) 
    cf = 0
    bu = [0] * len(baits)

    for f in fish:
        for i, bait in enumerate(baits):
            if bait < f and bu[i] < 3:
                cf += 1
                bu[i] += 1
                break

    return cf


Visa โœ…
๐Ÿ‘1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
vector<string> solve(vector<vector<string>> p, vector<string> a, int w) {
    vector<string> r;
    r.push_back(string(w + 2, '*'));
    for(int i = 0; i < p.size(); i++) {
        string l = "";
        for(string wd : p[i]) {
            if(l.size() + wd.size() + (l.empty() ? 0 : 1) > w) {
                if(a[i] == "LEFT") {
                    l += string(w - l.size(), ' ');
                } else if(a[i] == "RIGHT") {
                    l = string(w - l.size(), ' ') + l;
                }
                r.push_back("*" + l + "*");
                l = "";
            }
            if(!l.empty()) {
                l += " ";
            }
            l += wd;
        }
        if(!l.empty()) {
            if(a[i] == "LEFT") {
                l += string(w - l.size(), ' ');
            } else if(a[i] == "RIGHT") {
                l = string(w - l.size(), ' ') + l;
            }
            r.push_back("*" + l + "*");
        }
    }
    r.push_back(string(w + 2, '*'));
    return r;
}

Visa โœ…
SELECT DISTINCT 
    p.FIRST_NAME,
    p.CONTACT
FROM
    passenger p
JOIN
    boardingpass bp ON p.PASSENGER_ID = bp.PASSENGER_ID
JOIN
    flight f ON bp.FLIGHT_ID = f.FLIGHT_ID
WHERE
    f.FLIGHT_FROM = 'Hong Kong'
    AND bp.FLIGHT_ID = 4
    AND bp.MEAL = 'Vegetarian';


Cognizant โœ…
class UserMainCode(object):
    @classmethod
    def totalCount(cls, input1, input2, input3):
        N = input1
        X = input2
        A = input3 
        count = 0
        end = 0
        for start in range(N):
            while end < N and A[start] + A[end] <= X:
                end += 1
            count += (end - start)
        return count


Cognizant โœ…
๐Ÿ‘1
import java.util.*;
public class MagicalLibrary {
    public static int countMagicalRows(int[][] matrix) {
        int magicalRowCount = 0;
       
        for (int[] row : matrix) {
            int oddSum = 0;
            boolean hasOdd = false;
           
            for (int value : row) {
                if (value % 2 != 0) {
                    oddSum += value;
                    hasOdd = true;
                }
            }
            if (hasOdd && oddSum % 2 == 0) {
                magicalRowCount++;
            }
        }
       
        return magicalRowCount;
    }


magical libraryโœ…
Cognizant
public class HouseVisitCounter {
    public static int countHouses(int N, int[] A) {
        int houseCount = 1;
        int i = 1;
        while (i <= N) {
            int jump = A[i - 1];
            i = i + jump;
            if (i <= N) {
                houseCount++;
            } else {
                break;
            }
        }

        return houseCount;
    }

 House visitโœ…
Cognizant
๐Ÿ”ฅ1
import java.util.Arrays;
import java.util.Collections;
public class MinimumSum {
    public static int findMinimumSum(int N, int[] A, int[] B) {
        Arrays.sort(A);
        Integer[] B_desc = new Integer[N];
        for (int i = 0; i < N; i++) {
            B_desc[i] = B[i];
        }
        Arrays.sort(B_desc, Collections.reverseOrder());
        int minSum = 0;
        for (int i = 0; i < N; i++) {
            minSum += A[i] * B_desc[i];
        }

        return minSum;
    }


Minimum Sum โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
public class BobMathTeacher {
        private static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static int max_balls(int N, int[] marks) {
        if (N == 1) {
            return marks[0];
        }
        int[] prefixGCD = new int[N];
        int[] suffixGCD = new int[N];
        prefixGCD[0] = marks[0];
        for (int i = 1; i < N; i++) {
            prefixGCD[i] = gcd(prefixGCD[i - 1], marks[i]);
        }
        suffixGCD[N - 1] = marks[N - 1];
        for (int i = N - 2; i >= 0; i--) {
            suffixGCD[i] = gcd(suffixGCD[i + 1], marks[i]);
        }
        int maxGCD = 0;
        for (int i = 0; i < N; i++) {
            int gcdWithoutI;
            if (i == 0) {
                gcdWithoutI = suffixGCD[1];
            } else if (i == N - 1) {
                gcdWithoutI = prefixGCD[N - 2];
            } else {
                gcdWithoutI = gcd(prefixGCD[i - 1], suffixGCD[i + 1]);
            }
            maxGCD = Math.max(maxGCD, gcdWithoutI);
        }

        return maxGCD;
    }


Maximum Balls โœ…
#include <iostream>
#include <bitset>
#include <string>
using namespace std;
bool ss(const string& binaryStr) {
    return binaryStr.find("00") == string::npos;
}
int main() {
    int m, n;
    cin >> m >> n;
    if (m > 0 && n > 0 && n > m + 1) {
        for (int i = m + 1; i < n; ++i) {
            string a = bitset<32>(i).to_string();
            a = a.substr(a.find('1'));
            if (ss(a)) {
                cout << a << endl;
            }
        }
    } else {
        cout << "Invalid input: ensure m, n > 0 and there is at least one integer between m and n." << endl;
    }

    return 0;
}


Deloitte โœ…
#include<bits/stdc++.h>
using namespace std;
vector<int> solution(int N, int K, vector<int> seat) {
    set<int> availableSeats;
    for (int i = 1; i <= N; ++i) {
        availableSeats.insert(i);
    }
    vector<int> result;
    for (int i = 0; i < K; ++i) {
        if (seat[i] == 0) {
            int reservedSeat = *availableSeats.begin();
            availableSeats.erase(availableSeats.begin());
            result.push_back(reservedSeat);
        } else {
            availableSeats.insert(seat[i]);
        }
    }

    return result;
}

Sirion โœ