๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.52K subscribers
5.55K photos
3 videos
95 files
9.64K 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 java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int T = scanner.nextInt();
        while (T-- > 0) {
            int N = scanner.nextInt();
            int M = scanner.nextInt();
            int K = scanner.nextInt();

            Map<String, Integer> rowCount = new HashMap<>();

            for (int i = 0; i < N; i++) {
                StringBuilder rowPattern = new StringBuilder();
                for (int j = 0; j < M; j++) {
                    int val = scanner.nextInt();
                    rowPattern.append(val);
                }
                String pattern = rowPattern.toString();
                rowCount.put(pattern, rowCount.getOrDefault(pattern, 0) + 1);
            }

            int maxEqualRows = 0;
            Set<String> processedPatterns = new HashSet<>();

            for (String pattern : rowCount.keySet()) {
                if (processedPatterns.contains(pattern)) {
                    continue;
                }

                StringBuilder complementBuilder = new StringBuilder();
                for (int i = 0; i < pattern.length(); i++) {
                    complementBuilder.append(pattern.charAt(i) == '0' ? '1' : '0');
                }
                String complement = complementBuilder.toString();

                int countPattern = rowCount.get(pattern);
                int countComplement = rowCount.getOrDefault(complement, 0);

                int inversionsNeeded = Math.min(countPattern, countComplement);

                if (inversionsNeeded <= K) {
                    int totalRows = countPattern + countComplement;
                    maxEqualRows = Math.max(maxEqualRows, totalRows);
                }

                processedPatterns.add(pattern);
                processedPatterns.add(complement);
            }

            System.out.println(maxEqualRows);
        }

        scanner.close();
    }
}


Equal Rows โœ…
Google
long long minimumHealth(vector<int>& damage, int armor) {
        long long s = 0;
        int mx = damage[0];
        for (int& v : damage) {
            s += v;
            mx = max(mx, v);
        }
        return s - min(mx, armor) + 1;
    }

Amazon โœ…
#include <vector>
#include <iostream>
using namespace std;
int longestDiagonalSegment(vector<vector<int>>& matrix) {
    int rows = matrix.size();
    int cols = matrix[0].size();
    int longest = 0;
    int dR[] = {-1, 1, -1, 1};
    int dC[] = {1, 1, -1, -1}; 
    for (int r = 0; r < rows; ++r) {
    for (int c = 0; c < cols; ++c) {
    for (int dir = 0; dir < 4; ++dir) {
    int len = 0;
    int rPos = r, cPos = c;
    int pattern[] = {1, 2, 0, 2, 0, 2, 0};
    int pIdx = 0;
    while (rPos >= 0 && rPos < rows && cPos >= 0 && cPos < cols) {
    if (matrix[rPos][cPos] == pattern[pIdx]) {
        ++len;
        pIdx = (pIdx + 1) % 7;
        } else {
        break;
        }
        rPos += dR[dir];
        cPos += dC[dir];
        }
               
        longest = max(longest, len);
            }
        }
    }

    return longest;
}


Visa โœ…
def getRank(coffee, chocolate, query):
    n = len(coffee)
    drinks = [(coffee[i], chocolate[i], i+1) for i in range(n)]
    drinks.sort(key=lambda x: (-x[0], -x[1], x[2]))
    result = [drinks[q-1][2] for q in query]
    return result

DE Shaw โœ…
def canonical_form(s):
    mapping = {}
    form = []
    next_index = 0

    for char in s:
        if char not in mapping:
            mapping[char] = next_index
            next_index += 1
        form.append(mapping[char])

    return tuple(form)

def solve(N, Q, S, K):
    canonical_map = {}

    for string in S:
        form = canonical_form(string)
        if form not in canonical_map:
            canonical_map[form] = 0
        canonical_map[form] += 1

    result = []
    for query in K:
        query_form = canonical_form(query)
        result.append(canonical_map.get(query_form, 0))

    return result

Google โœ…
#include <vector>
using namespace std;

vector<int> solution(vector<int> forest, int bird) {
    vector<int> pos;
    int total_length = 0;
    int direction = 1;
    int n = forest.size();
    while (total_length < 100) {
        if (direction == 1) {
            for (int i = bird + 1; i < n; i++) {
                if (forest[i] > 0) {
                    pos.push_back(i);
                    total_length += forest[i];
                    forest[i] = 0;
                    break;
                }
            }
        } else {
            for (int i = bird - 1; i >= 0; i--) {
                if (forest[i] > 0) {
                    pos.push_back(i);
                    total_length += forest[i];
                    forest[i] = 0;
                    break;
                }
            }
        }
        direction *= -1;
    }
    return pos;
}


Visa โœ