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

#define int long long

int solution(int n, vector<vector<int>>& edges) {
    vector<vector<int>> v(n + 1);
    vector<int> indegree(n + 1, 0);

    for (auto& edge : edges) {
        int u = edge[0], v1 = edge[1];
        v[u].push_back(v1);
        v[v1].push_back(u);
        indegree[v1]++;
        indegree[u]++;
    }

    vector<int> vis(n + 1, 0);
    queue<int> q;

    for (int i = 1; i <= n; i++) {
        if (indegree[i] == 1) {
            q.push(i);
            break;
        }
    }

    int c = 0;
    for (int i = 1; i <= n; i++) {
        if (indegree[i] == 0) {
            c++;
        }
    }

    if (q.empty()) {
        return -1;
    }

    while (!q.empty()) {
        int size = q.size();
        c++;
        for (int i = 0; i < size; i++) {
            auto node = q.front(); q.pop();
            if (vis[node]) continue;
            vis[node] = 1;

            for (auto x : v[node]) {
                if (!vis[x]) {
                    q.push(x);
                }
            }
        }
    }

    return c;
}
Cab Credit
Uber intern โœ…
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int min_sum_time(vector<int>& time) {
    sort(time.begin(), time.end());
    int total_time = 0;
    int current_sum = 0;
    for (int t : time) {
        current_sum += t;
        total_time += current_sum;
    }
    return total_time;
}

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

vector<vector<string>> solution(vector<string> apiList, vector<vector<long long>> rateLimits, vector<long long> defaultLimits, vector<vector<string>> requests) {
   
    struct RateLimit {
        long long limit;
        long long interval;
    };
   
    struct Request {
        string type;
        long long timestamp;
    };
   
    unordered_map<string, RateLimit> apiRateMap;
    for (size_t i = 0; i < apiList.size(); ++i) {
        apiRateMap[apiList[i]] = {rateLimits[i][0], rateLimits[i][1]};
    }


    unordered_map<string, queue<long long>> apiReqMap;
    unordered_map<string, long long> denied;

    for (const auto& req : requests) {
        string api = req[0];
        long long timestamp = stoll(req[1]);

        RateLimit rl = (apiRateMap.find(api) != apiRateMap.end()) ? apiRateMap[api] : RateLimit{defaultLimits[0], defaultLimits[1]};

        auto& q = apiReqMap[api];
       
        while (!q.empty() && q.front() <= timestamp - rl.interval) {
            q.pop();
        }

        if (q.size() < rl.limit) {
            q.push(timestamp);
        } else {
            denied[api]++;
        }
    }

    vector<vector<string>> result;
    for (const auto& entry : denied) {
        result.push_back({entry.first, to_string(entry.second)});
    }

    sort(result.begin(), result.end());
   
    return result;
}

Uber (intern) โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int min_time_to_enter_room(int n, vector<vector<int>>& entryTime) {
    vector<vector<int>> directions = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    vector<vector<int>> earliest_time(n, vector<int>(n, INT_MAX));
    priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<>> pq;
    pq.push({0, {0, 0}});
    earliest_time[0][0] = 0;
   
    while (!pq.empty()) {
        int current_time = pq.top().first;
        int x = pq.top().second.first;
        int y = pq.top().second.second;
        pq.pop();
       
        if (x == n - 1 && y == n - 1) return current_time;
       
        for (auto& dir : directions) {
            int nx = x + dir[0];
            int ny = y + dir[1];
            if (nx >= 0 && ny >= 0 && nx < n && ny < n) {
                int next_time = max(current_time, entryTime[nx][ny]);
                if (next_time < earliest_time[nx][ny]) {
                    earliest_time[nx][ny] = next_time;
                    pq.push({next_time, {nx, ny}});
                }
            }
        }
    }
   
    return -1;
}
Uber (intern) โœ…
๐Ÿ‘1
Exciting Opportunity for freshers to Kickstart their Career โค๏ธโค๏ธโค๏ธ๐Ÿ’ฅ๐Ÿ’ฅ๐Ÿ’ฅ๐Ÿ’ช๐Ÿ’ช๐Ÿ’ช

Freshers WalkIn Alert ๐Ÿ”ฅ๐Ÿ”ฅ

Process- Back Office

Eligibility - Only Fresher/ Intern

Graduate- 2021 or above

Note- BE/B.Tech are not eligible.

Location: Gurgaon

Date of Interview: 23rd August, 2024.
Time: 10 AM

Address: 8th Floor, Big Audi, Tower C, Building 14, Sector 24 & 25 A, Gurugram- 122001.

Things to Carry:
Aadhaar Card
2 Copy of Resume

To confirm attendance, email
harmeet.2.singh@bt.com with "Yes, I will be coming" for prior security approval.
๐Ÿ‘2
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include<climits>
using namespace std;

const int MOD = 1e9 + 7;

class Solution {
public:
    int removeIntegers(int N, int P, int Q, vector<int>& special_integers) {
        sort(special_integers.begin(), special_integers.end());
        unordered_map<int, bool> is_special;
        for (int num : special_integers)
            is_special[num] = true;

        return minCost(1, 1 << N, P, Q, is_special);
    }

private:
    int minCost(int start, int end, int P, int Q, unordered_map<int, bool>& is_special) {
        int length = end - start + 1;

        if (length == 1) {
            return is_special[start] ? P : Q;
        }

        if (is_power_of_two(length)) {
            return is_special[start] ? (P * length) : Q;
        }

        int min_cost = INT_MAX;

        for (int mid = start; mid < end; ++mid) {
            int left_length = mid - start + 1;
            int right_length = end - mid;

            int left_cost = minCost(start, mid, P, Q, is_special);
            int right_cost = minCost(mid + 1, end, P, Q, is_special);

            min_cost = min(min_cost, left_cost + right_cost);
        }

        min_cost = min(min_cost, is_special[start] ? (P * length) : Q);

        return min_cost;
    }

    bool is_power_of_two(int n) {
        return (n & (n - 1)) == 0;
    }
};

BNYโœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
import java.util.*;

public class Main {
    static int countUniqueSubsets(int[] arr, int N, int K) {
        Arrays.sort(arr);
        return countUniqueSubsetsUtil(arr, N, K, 0, 0);
    }
   
    static int countUniqueSubsetsUtil(int[] arr, int N, int K, int currentIndex, int currentSum) {
        if (currentSum == K) {
            return 1;
        }
        if (currentSum > K || currentIndex >= N) {
            return 0;
        }
       
        int count = 0;
       
     
        count += countUniqueSubsetsUtil(arr, N, K, currentIndex + 1, currentSum + arr[currentIndex]);
       
     
        while (currentIndex + 1 < N && arr[currentIndex] == arr[currentIndex + 1]) {
            currentIndex++;
        }

   
        count += countUniqueSubsetsUtil(arr, N, K, currentIndex + 1, currentSum);
       
        return count;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        int[] arr = new int[N];
       
        for (int i = 0; i < N; i++) {
            arr[i] = scanner.nextInt();
        }
       
        System.out.println(countUniqueSubsets(arr, N, K));
    }
}

The puzzle masters of puzzleville โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
import java.util.*;
import java.io.*;

class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine();
        int indent = 0;
        boolean inQuotes = false;
        StringBuilder output = new StringBuilder();

        for (char ch : input.toCharArray()) {
            switch (ch) {
                case '{':
                case '[':
                    output.append(ch);
                    if (!inQuotes) {
                        output.append("\n");
                        indent++;
                        appendIndentation(output, indent);
                    }
                    break;
                case '}':
                case ']':
                    if (!inQuotes) {
                        output.append("\n");
                        indent--;
                        appendIndentation(output, indent);
                    }
                    output.append(ch);
                    break;
                case ',':
                    output.append(ch);
                    if (!inQuotes) {
                        output.append("\n");
                        appendIndentation(output, indent);
                    }
                    break;
                case '"':
                    output.append(ch);
                    inQuotes = !inQuotes;
                    break;
                default:
                    output.append(ch);
                    break;
            }
        }
        System.out.println(output.toString());
    }

    private static void appendIndentation(StringBuilder sb, int indent) {
        for (int i = 0; i < indent; i++) {
            sb.append("**");
        }
    }
}

Json formatter โœ