๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.57K subscribers
5.58K photos
3 videos
95 files
9.96K 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
import math

def getDataDependenceSum(n):
    m = int(math.isqrt(n))
    maxSmallX = n // m
    sumSmallX = (maxSmallX * (maxSmallX + 1)) // 2
    myst1c = sumSmallX
    for k in range(1, m + 1):
        x = n // k
        if x > maxSmallX:
            myst1c += x
    return myst1c
import java.util.TreeSet;
public class Main {
    public int TaichiAndLand(int n, int m, int[][] arr, int K) {
        int maxSum = Integer.MIN_VALUE;
        for (int top = 0; top < n; top++) {
            int[] columnSum = new int[m];
            for (int bottom = top; bottom < n; bottom++) {
                for (int col = 0; col < m; col++) {
                    columnSum[col] += arr[bottom][col];
                }
                maxSum = Math.max(maxSum, solve(columnSum, K));
            }
        }

        return maxSum;
    }
    private int solve(int[] nums, int K) {
        int sum = 0;
        int maxSum = Integer.MIN_VALUE;
        TreeSet<Integer> cc = new TreeSet<>();
        cc.add(0);

        for (int num : nums) {
            sum += num;
            Integer prefix = cc.ceiling(sum - K);
            if (prefix != null) {
                maxSum = Math.max(maxSum, sum - prefix);
            }

            cc.add(sum);
        }

        return maxSum;
    }



taichi and land โœ…
Probo(intern)
import java.util.*;
public class Main {
    static class DSU {
        int[] parent, size;
        public DSU(int n) {
            parent = new int[n];
            size = new int[n];
            for (int i = 0; i < n; i++) {
                parent[i] = i;
                size[i] = 1;  
            }
        }
        public int find(int x) {
            if (parent[x] != x) {
                parent[x] = find(parent[x]);
            }
            return parent[x];
        }
        public void union(int x, int y) {
            int rootX = find(x);
            int rootY = find(y);
            if (rootX != rootY) {
                if (size[rootX] < size[rootY]) {
                    parent[rootX] = rootY;
                    size[rootY] += size[rootX];
                } else {
                    parent[rootY] = rootX;
                    size[rootX] += size[rootY];
                }
            }
        }
    }
    public static int solution(int n, int p, int[][] programmers) {
        DSU dsu = new DSU(n);
                for (int i = 0; i < p; i++) {
            int u = programmers[i][0];
            int v = programmers[i][1];
            dsu.union(u, v);
        }
        Map<Integer, Integer> componentSize = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int root = dsu.find(i);
            componentSize.put(root, componentSize.getOrDefault(root, 0) + 1);
        }
        long totalPairs = (long) n * (n - 1) / 2;
                for (int size : componentSize.values()) {
            totalPairs -= (long) size * (size - 1) / 2;
        }

        return (int) totalPairs;
    }


Contest pair โœ…
Probo (intern)
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
import java.util.Scanner;
public class ColorChange {
    private static void solve(int[][] image, int row, int col, int newColor, int originalColor) {
        if (row < 0 || row >= image.length || col < 0 || col >= image[0].length) {
            return;
        }
        if (image[row][col] != originalColor) {
            return;
        }
         image[row][col] = newColor;
        solve(image, row + 1, col, newColor, originalColor);
        solve(image, row - 1, col, newColor, originalColor);
        solve(image, row, col + 1, newColor, originalColor);
        solve(image, row, col - 1, newColor, originalColor);
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int rows = scanner.nextInt();
        int cols = scanner.nextInt();
        int[][] image = new int[rows][cols];
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                image[i][j] = scanner.nextInt();
            }
        }
        int sourceRow = scanner.nextInt();
        int sourceCol = scanner.nextInt();
        int newColor = scanner.nextInt();
        int originalColor = image[sourceRow][sourceCol];
        if (originalColor != newColor) {
            solve(image, sourceRow, sourceCol, newColor, originalColor);
        }
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                System.out.print(image[i][j] + " ");
            }
            System.out.println();
        }

        scanner.close();
    }
}

Changing colour in imageโœ…
๐Ÿ‘1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
import java.util.Scanner;

public class ClimbingStairs {

    public static int countWays(int n) {
        if (n == 1) return 1;
        if (n == 2) return 2;
        int[] dp = new int[n + 1];
        dp[1] = 1;
        dp[2] = 2;
        for (int i = 3; i <= n; i++) {
            dp[i] = dp[i - 1] + dp[i - 2];
        }
       
        return dp[n];
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int result = countWays(n);
        System.out.println(result);
        scanner.close();
    }
}

Staircase Adventure Court โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include<bits/stdc++.h>
using namespace std;
using ll = Long Long;

int mod = 1e9 + 7;
int dp[1000001][2][2][2];

int F(int i, int reqdParity, int currparity, int ended, vector<int> &A) {
    if (i < 0) return ended;

    if (dp[i][reqdParity][currparity][ended] != -1)
        return dp[i][reqdParity][currparity][ended];

    int newParity = (currparity + A[i]) % 2;

    ll Continue = F(i - 1, reqdParity, newParity, 0, A);
    ll EndHere = reqdParity == newParity ? F(i - 1, 1 - newParity, 0, 1, A) : 0;

    return dp[i][reqdParity][currparity][ended] = (Continue + EndHere) % mod;
}

int findNumberOfPartitions(int N, vector<int> A) {
    memset(dp, -1, sizeof(dp));
    return (F(N - 1, 0, 0, 0, A) + F(N - 1, 1, 0, 1, A)) % mod;
}


Number of partitions โœ…
Oracle
#include <iostream>
#include <vector>
#include <algorithm>
using ll = long long;
using namespace std;
int getMinimumUniqueSum(vector<int> &arr) {
    sort(arr.begin(), arr.end());
    ll sum = arr[0]; 
    for (int i = 1; i < arr.size(); i++) {
        if (arr[i] <= arr[i - 1]) {
            arr[i] = arr[i - 1] + 1;
        }
        sum += arr[i];
    }
   
    return sum;
}

PayPal โœ…
๐Ÿ‘1