๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.57K subscribers
5.58K photos
3 videos
95 files
9.99K 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
int solution(vector<int> arg1) {
    int n = arg1.size();
    int currentReach = 0;
    int maxReach = 0;
    int jumps = 0;

    for (int i = 0; i < n - 1; i++) {
        maxReach = max(maxReach, i + arg1[i]);
        if (i == currentReach) {
            currentReach = maxReach;
            jumps++;
        }
    }

    return jumps;
}
def countWays(k: int, n: int) -> int:
    MOD = 10**9 + 7
    dp = [[0 for _ in range(n + 1)] for __ in range(k + 1)]
    dp[1] = [0] + [1] * n
    for i in range(2, k + 1):
        total = sum(dp[i - 1])
        for j in range(1, n + 1):
            dp[i][j] = (total - dp[i - 1][j]) % MOD
return sum(dp[k]) % MOD


DTCC | Python โœ…
public class Solution {
    public static int getMaxLength(List<Integer> list) {
        int n = list.size();

        int[] freq = new int[32];
        for (int num : list) {
            for (int bit = 0; bit < 32; bit++) {
                if ((num & (1 << bit)) != 0) {
                    freq[bit]++;
                }
            }
        }

        int maxLen = 0;
        for (int i = 0; i < 32; i++) {
            maxLen = Math.max(maxLen, freq[i]);
        }

        return maxLen;
    }
}

Hackerrank
subsequence Length  โœ…
#include<bits/stdc++.h>
using namespace std;

int F(int x){
    int sum = 0;
    while(x){
        sum += x%10;
        x /= 10;
    }
    return sum;
}

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    int max_x = max(b, c) * pow(9, a) + c;
    int max_digits = floor(log10(max_x) + 1);
    int max_Fx = 9 * max_digits;

    vector<int> solutions;
    for(int sum = 1; sum <= max_Fx; sum++){
        int x = b * pow(sum, a) + c;
        if(x <= max_x && sum == F(x)){
            solutions.push_back(x);
        }
    }

    cout << solutions.size() << endl;
    for(int x : solutions){
        cout << x << " ";
    }
    cout << endl;
    return 0;
}

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

typedef long long ll;
const ll INF = 1e18;
int N;
vector<pair<ll,ll>> trees;

ll Manhattan(pair<ll,ll> a, pair<ll,ll> b) {
    return abs(a.first - b.first) + abs(a.second - b.second);
}

ll findMinDistance() {
    sort(trees.begin(), trees.end());
    ll minDist = INF;
    for(int i = 1; i < N; i++) {
        minDist = min(minDist, Manhattan(trees[i], trees[i-1]));
    }
    return minDist;
}

ll findMaxDistance() {
    ll mx1 = -INF, mx2 = -INF, mn1 = INF, mn2 = INF;
    for(int i = 0; i < N; i++) {
        mx1 = max(mx1, trees[i].first + trees[i].second);
        mn1 = min(mn1, trees[i].first + trees[i].second);
        mx2 = max(mx2, trees[i].first - trees[i].second);
        mn2 = min(mn2, trees[i].first - trees[i].second);
    }
    return max(mx1 - mn1, mx2 - mn2);
}

void solve() {
    ll minMaxDist = INF, maxMinDist = -INF;
    for(int i = 0; i < N; i++) {
        pair<ll,ll> temp = trees[i];
        trees.erase(trees.begin() + i);
        minMaxDist = min(minMaxDist, findMaxDistance());
        maxMinDist = max(maxMinDist, findMinDistance());
        trees.insert(trees.begin() + i, temp);
    }
    cout  << minMaxDist << '\n';
    cout << maxMinDist << '\n';
}

int main() {
    cin >> N;
    trees.resize(N);
    for(int i = 0; i < N; i++) {
        cin >> trees[i].first >> trees[i].second;
    }
    solve();
    return 0;
}
Maximum and Minimum distance โœ…
#include<bits/stdc++.h>
using namespace std;

int countOccurrences(int num, int k) {
    string numStr = to_string(num);
    return count(numStr.begin(), numStr.end(), '0' + k);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k, n;
    cin >> k;
    cin >> n;
    if(n == 0) {
        cout << -1;
        return 0;
    }
    vector<int> arr(n);
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    int maxCount = -1;
    int number = 0;
    for(int i = 0; i < n; i++) {
        int currentCount = countOccurrences(arr[i], k);
        if(currentCount > maxCount) {
            maxCount = currentCount;
            number = arr[i];
        }
    }
    if(maxCount == 0) {
        cout << 0;
    } else {
        cout << number;
    }
    return 0;
}
C++โœ…
TCS Mega Walk-in Drive

Location:  Hyderabad

Qualification: BCom, B.A, BBA, BSc (all streams), BCA, BMS, BAF, BBI

Batch: 2021, 2022 and 2023 batch

Salary: 3.4 LPA (Expected)

Walkin Date: Hyderabad (5th Aug 23)

Drive Venue: TCS Deccan park, Plot No 1, Software Units Layout, Madhapur, Hyderabad, Telangana 500081

Timings: 9 AM to 11 AM
#include <bits/stdc++.h>
#include <boost/icl/interval_set.hpp>
using namespace std;

vector<long long> solution(vector<vector<long long>>& chunks) {
    boost::icl::interval_set<long long> receivedBytes;
    vector<long long> result;
   
    for(auto &chunk: chunks) {
        receivedBytes.insert(boost::icl::discrete_interval<long long>::closed(chunk[0], chunk[1]));
        result.push_back(boost::icl::length(receivedBytes) - receivedBytes.iterative_size() + 1);
    }
    return result;
}

int main() {
    vector<vector<long long>> chunks = {{1, 9}, {1, 3}, {8, 15}, {6, 9}, {2, 3}};
    vector<long long> result = solution(chunks);
   
    for(auto res: result)
        cout << res << ' ';
    cout << '\n';
   
    return 0;
}

Counting Unique Bytes in Overlapping File Chunk
C++โœ…
#include<bits/stdc++.h>
using namespace std;

int minWealthDifference(vector<int>& c) {
    int totalWealth = accumulate(c.begin(), c.end(), 0);
    int n = c.size();
    int offset = n*10000;
    vector<vector<bool>> dp(n+1, vector<bool>(2*offset+1, false));

    dp[0][offset] = true;

    for(int i = 0; i < n; ++i){
        for(int j = i; j >= 0; --j){
            for(int k = 0; k <= 2*offset; ++k){
                if(dp[j][k]) {
                    dp[j+1][k+c[i]] = true;
                }
            }
        }
    }

    int result = INT_MAX;
    for(int i = 0; i <= 2*offset; ++i){
        if(dp[n/2][i]) {
            result = min(result, abs(totalWealth - 2*(i - offset)));
        }
    }
    return result;
}

int main() {
    int n;
    cin >> n;
    vector<int> c(n);
    for(int i = 0; i < n; ++i){
        cin >> c[i];
    }
    cout <<minWealthDifference(c) << "\n";

    return 0;
}

NATURE
C++โœ…
int solution(vector<int> arr, int src, int dest) {
    map<int,int> visA, visB;
    int start = arr[src];
    int curr = 1;
    set<int> s;

    for(auto &x: arr){
        s.insert(x);
    }

    while(visA[start] == 0){
        visA[start] = curr;
        curr++;
        start = arr[start];
        if(start == -1){
            break;
        }
    }
    start = arr[dest];

    while(visB[start] == 0){
        visB[start] = curr;
        curr++;
        start = arr[start];
        if(start == -1){
            break;
        }
    }

    vector<pair<int,int>> vp;
    for(auto &x: s){
        if(visA[x] != 0 && visB[x] != 0){
            pair<int,int> p = {visA[x] + visB[x], x};
            vp.push_back(p);
        }
    }

    sort(vp.begin(), vp.end());
    return vp[0].second;
}

Juspay Largest Sum Cycle
C++โœ…
int solution(vector<int>arr){
    int ans=INT_MIN;
    int result=-1;
    vector<int>weight(arr.size(),0);
    for(int i=0;i<arr.size();i++){
        int source=i;
        int dest=arr[i];
        if(dest!=-1){
            weight[dest]+=source;
            if(ans<=weight[dest]){
                ans=max(ans,weight[dest]);
                result=dest;
            }
           
        }
    }
    if(ans!=INT_MIN)
        return result;
    return -1;
}

Juspay Maximum Weight Node C++โœ…
int leastCommonDescendent(int nodes[], int N, int node1, int node2) {
    int *visited = new int [N];
    int cnt1 = 0;
    int cnt2 = 0;
    int mark = node1;

    if(node1 == node2) return node2;
    for(int i = 0; i < N; i++){
        visited[i] = 0;
    }

    while((nodes[node1] != node1) && (nodes[node1] != -1) && (visited[node1] == 0) && (node1 != node2)){
        visited[node1]++;
        node1 = nodes[node1];
        cnt1++;
    }

    visited[node1]++;

    while((nodes[node2] != node2) && (nodes[node2] != -1) && (visited[node2] != 2) && (node1 != node2)){
        visited[node2]++;
        node2 = nodes[node2];
        cnt2++;
    }

    if(node1 != node2) return -1;
    if ((nodes[node1] == -1) && (visited[node2] == 1)) return -1;
    if(nodes[node2] == -1) return -1;
    if(cnt1 > cnt2)
        return node2;
    else
        return mark;
}

Juspay Nearest Meeting Cell
C++โœ…
๐Ÿ‘1
#include <bits/stdc++.h>
using namespace std;

int main ()
{
  int64_t n, m, k; cin >> n >> m >> k;
  vector<pair<int64_t, int64_t>> pts(k);
  for (auto &[x, y] : pts)
    cin >> x >> y;

  int64_t r; cin >> r;
  int64_t t; cin >> t;
  int64_t rt = r*t;

  int64_t cnt = 0;
 
  for (int64_t x = 0; x <= n; x++) {
    for (int64_t y = 0; y <= n; y++) {
      bool burn = 0;
      for (auto [fx, fy] : pts) {
auto dx = x - fx;
auto dy = y - fy;

auto ri = dx*dx + dy*dy;
if (ri <= rt*rt) { burn = 1; break; }
      }
      //      cout << x << " " << y << endl;
      if (!burn) cnt++;
    }
  }
  cout << cnt << endl;

}


Spreading fire
Intuitโœ…
๐Ÿ‘1
#include <stdio.h>
#include <stdlib.h>

int min(int x, int y) { return x < y ? x : y; }
int max(int x, int y) { return x > y ? x : y; }

int n, m, t, fx, fy, ix, iy, jx, jy;

int vis[1005][1005];
bool solve(int x, int y, int t)
{
  if (x < 0 || y < 0) return 0;
  if (x >= m || y >= m) return 0;
  if (abs(x-fx) + abs(y - fy) <= t) return 0;
  if (x == jx && y == jy) return 1;
  if (vis[x][y] <= t) return 0;
  vis[x][y] = t;
  return solve(x+1, y, t+1)  solve(x-1, y, t+1)  solve(x, y+1, t+1) || solve(x, y-1, t+1);
}


int main() {

    scanf("%d %d", &n, &m);

    scanf("%d", &t);
   
    while (t--) {
      for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
   vis[i][j] = 0x3f3f3f3f;
}
      }
     
        scanf("%d %d %d %d %d %d", &fx, &fy, &ix, &iy, &jx, &jy);
        bool res = solve(ix, ix, 0);
       
        if (!res) {
            printf("NO\n");
        } else {
            printf("YES\n");
        }
    }

    return 0;
}


Circus Fire 1โœ