๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.61K 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
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <bits/stdc++.h>

using namespace std;

string ltrim(const string &);
string rtrim(const string &);


/*
* Complete the 'isConsistent' function below.
*
* The function is expected to return a BOOLEAN.
* The function accepts STRING_ARRAY expressions as parameter.
*/

bool isConsistent(vector<string> expressions) {
    unordered_map<char, vector<char>> graph; 
    unordered_map<char, int> indegree;       
    for (char c = 'a'; c <= 'z'; c++) {
        indegree[c] = 0;
    }
   
    for (string expr : expressions) {
        char u = expr[0]; 
        char v = expr[2]; 
       
        graph[v].push_back(u); 
        indegree[u]++;         
    }
   
    queue<char> q;
   
    for (char c = 'a'; c <= 'z'; c++) {
        if (indegree[c] == 0) {
            q.push(c);
        }
    }
   
    int visitedCount = 0; 
    while (!q.empty()) {
        char u = q.front();
        q.pop();
        visitedCount++;
       
        for (char v : graph[u]) {
            indegree[v]--;
            if (indegree[v] == 0) {
                q.push(v);
            }
        }
    }
   

    return visitedCount == 26;
}

Codevilla Numeric Quest
Salesforceโœ…
int solve(vector<int>& arr, int x) {
    int n = arr.size();
    int total = accumulate(arr.begin(), arr.end(), 0);
    int target = total - x;
   
    if (target < 0) return -1;
    if (target == 0) return n;

    int maxi = -1, curr = 0;
    unordered_map<int, int> pm;
    pm[0] = -1;

    for (int i = 0; i < n; ++i) {
        curr += arr[i];
       
        if (pm.find(curr - target) != pm.end()) {
            maxi = max(maxi, i - pm[curr - target]);
        }
       
        pm[curr] = i;
    }

    return maxi == -1 ? -1 : n - maxi;
}

Codevilla numeric questโœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <bits/stdc++.h>

using namespace std;

string ltrim(const string &);
string rtrim(const string &);



/*
* Complete the 'minNumberOfLights' function below.
*
* The function is expected to return an INTEGER.
* The function accepts following parameters:
*  1. INTEGER_ARRAY A
*  2. INTEGER P
*/

int minNumberOfLights(vector<int> A, int P) {
int n = A.size();
    int lamps_on = 0;
    int i = 0;

    while (i < n) {
        int furthest_cover = -1;

        for (int j = max(0, i - P + 1); j < std::min(n, i + P); ++j) {
            if (A[j] == 1) {
                furthest_cover = j + P - 1;
            }
        }

        if (furthest_cover == -1) {
            return -1;
        }

        lamps_on++;
        i = furthest_cover + 1;
    }

    return lamps_on;
}

Luminous Passage Quest
Salesforce โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <set>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

string strip(const string& h) {
    if (h.substr(0, 4) == "www.") return h.substr(4);
    if (h.substr(0, 4) == "ww2.") return h.substr(4);
    if (h.substr(0, 4) == "web.") return h.substr(4);
    return h;
}

string extractDomain(const string& u) {
    string p_http = "http://";
    string p_https = "https://";
    size_t p_pos = string::npos;
    if (u.substr(0, p_http.size()) == p_http) p_pos = p_http.size();
    else if (u.substr(0, p_https.size()) == p_https) p_pos = p_https.size();
    if (p_pos == string::npos) return "";
    size_t e_pos = u.find('/', p_pos);
    string h = (e_pos == string::npos) ? u.substr(p_pos) : u.substr(p_pos, e_pos - p_pos);
    return strip(h);
}

vector<string> extractURLs(const string& l) {
    vector<string> urls;
    size_t s = 0;
    while ((s = l.find("http://", s)) != string::npos || (s = l.find("https://", s)) != string::npos) {
        size_t e = l.find_first_of(" \n)", s);
        if (e == string::npos) e = l.length();
        urls.push_back(l.substr(s, e - s));
        s = e;
    }
    return urls;
}

string getPotentialDomains(const vector<string>& lines) {
    set<string> d_set;
    for (const string& l : lines) {
        vector<string> urls = extractURLs(l);
        for (const string& u : urls) {
            string d = extractDomain(u);
            if (!d.empty() && count(d.begin(), d.end(), '.') >= 1) d_set.insert(d);
        }
    }
    vector<string> sorted_d(d_set.begin(), d_set.end());
    string res;
    for (size_t i = 0; i < sorted_d.size(); ++i) {
        if (i > 0) res += ";";
        res += sorted_d[i];
    }
    return res;
}

Standard Chartered โœ…
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 โœ