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

int find(vector<vector<int>>&mat)

{

int n=mat.size();

int m=mat[0].size();

vector<pair<int,int>>d={{-1,0},{1,0},{0,-1},{0,1}};

queue<pair<int,int>>q;

for(int i=0;i<n;i++)

{

for(int j=0;j<m;j++)

{

if(mat[i][j]==2)

{

q.push({i,j});

mat[i][j]=1;

}

}

}

int level=0;

while(!q.empty())

{

int size=q.size();

for(int i=0;i<size;i++)

{

auto temp=q.front();

q.pop();

int x=temp.first;

int y=temp.second;

if(x==0||y==0||x==n-1||y==m-1)

{

return level;

}

for(auto it:d)

{

int nx=x+it.first;

int ny=y+it.second;

if(nx>=0&&ny>=0&&nx<n&&ny<m&&mat[nx][ny]==0)

{

mat[nx][ny]=1;

q.push({nx,ny});

}

}

}

level++;

}

return -1;

}

int main()

{

int n,m;

cin>>n>>m;

vector<vector<int>>mat(n,vector<int>(m));

for(int i=0;i<n;i++)

{

for(int j=0;j<m;j++)

{

cin>>mat[i][j];

}

}

cout<<find(mat)<<endl;

}


Escape from Grid โœ…
#include <iostream>
#include <unordered_map>
#include <string>
using namespace std;
int main() {
    int n;
    cin >> n; 
    string str;
    cin >> str; 
    unordered_map<char, int> v;
    v['a'] = 0;
    v['e'] = 0;
    v['i'] = 0;
    v['o'] = 0;
    v['u'] = 0;
        for (char c : str) {
        if (v.find(c) != v.end()) {
            v[c]++;
        }
    }
    char m = 'a';
    int e = v['a'];
    for (auto &pair : v) {
        if (pair.second > e) {
            m = pair.first;
            e = pair.second;
        }
    }
        cout << m << endl;
   
    return 0;
}


Most frequent vowel โœ…
HSBC
#include <iostream>
#include <string>
using namespace std;
const int MOD = 1000000007;
int main() {
    int n;
    cin >> n;
    string s;
    cin >> s; 
        if (n == 1) {
        cout << 2 << endl;
        return 0;
    }
        int a = 0;
        for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            string r = s.substr(0, i) + s.substr(j + 1);
            if (r.empty() || r.find_first_not_of(r[0]) == string::npos)
            {
                a++;
            }
        }
    }
        cout << a % MOD << endl;
    return 0;
}


Powerful strings โœ…
import java.util.Scanner;

public class KeypadStrokes {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String str = sc.next();
       
        int[] times = new int[26];
        times['a' - 'a'] = 1; times['b' - 'a'] = 2; times['c' - 'a'] = 3;
        times['d' - 'a'] = 1; times['e' - 'a'] = 2; times['f' - 'a'] = 3;
        times['g' - 'a'] = 1; times['h' - 'a'] = 2; times['i' - 'a'] = 3;
        times['j' - 'a'] = 1; times['k' - 'a'] = 2; times['l' - 'a'] = 3;
        times['m' - 'a'] = 1; times['n' - 'a'] = 2; times['o' - 'a'] = 3;
        times['p' - 'a'] = 1; times['q' - 'a'] = 2; times['r' - 'a'] = 3; times['s' - 'a'] = 4;
        times['t' - 'a'] = 1; times['u' - 'a'] = 2; times['v' - 'a'] = 3;
        times['w' - 'a'] = 1; times['x' - 'a'] = 2; times['y' - 'a'] = 3; times['z' - 'a'] = 4;

        int totalTime = 0;
        for (int i = 0; i < n; i++) {
            totalTime += times[str.charAt(i) - 'a'];
            if (i > 0 && (getButton(str.charAt(i)) == getButton(str.charAt(i - 1)))) {
                totalTime++;
            }
        }
        System.out.println(totalTime);
    }

    private static int getButton(char ch) {
        if (ch >= 'a' && ch <= 'c') return 2;
        if (ch >= 'd' && ch <= 'f') return 3;
        if (ch >= 'g' && ch <= 'i') return 4;
        if (ch >= 'j' && ch <= 'l') return 5;
        if (ch >= 'm' && ch <= 'o') return 6;
        if (ch >= 'p' && ch <= 's') return 7;
        if (ch >= 't' && ch <= 'v') return 8;
        if (ch >= 'w' && ch <= 'z') return 9;
        return -1;
    }
}

Keypad strokes
HSBCโœ…
#include <bits/stdc++.h>
using namespace std;
#define int long long
using namespace std;
int solution(vector<int> &A) {
    int n = A.size();
    int m = 0;
    int i = 0;
    while (i < n - 1) {
        if (A[i] >= A[i + 1]) {
            int j = i + 1;
            while (j < n && A[j] <= A[j - 1]) {
                j++;
            }
                        m++;
                        i = j;
        } else {
            i++;
        }
    }
   
    return m;
}


Eagleview โœ…
SELECT 
    c.mac,
    SUM(t.amount) AS traffic,
    ROUND(SUM(t.amount) * c.tariff, 2) AS cost
FROM
    clients c
JOIN
    traffic t ON c.id = t.client_id
WHERE
    t.dt LIKE '2022-05%'
GROUP BY
    c.mac, c.tariff
ORDER BY
    cost DESC;


IBMโœ…
def largest_x(matrix):
    R, C = len(matrix), len(matrix[0])
    lu = [[0]*C for _ in range(R)]
    ru = [[0]*C for _ in range(R)]
    ld = [[0]*C for _ in range(R)]
    rd = [[0]*C for _ in range(R)]
   
    for r in range(R):
        for c in range(C):
            if matrix[r][c]:
                lu[r][c] = 1 + (lu[r-1][c-1] if r and c else 0)
                ru[r][c] = 1 + (ru[r-1][c+1] if r and c < C-1 else 0)
               
    for r in range(R-1, -1, -1):
        for c in range(C):
            if matrix[r][c]:
                ld[r][c] = 1 + (ld[r+1][c-1] if r < R-1 and c else 0)
                rd[r][c] = 1 + (rd[r+1][c+1] if r < R-1 and c < C-1 else 0)
   
    max_size, res = 0, [0,0]
    for r in range(R):
        for c in range(C):
            if matrix[r][c]:
                s = min(lu[r][c], ru[r][c], ld[r][c], rd[r][c])
                if s > max_size or (s == max_size and (r < res[0] or (r == res[0] and c < res[1]))):
                    max_size, res = s, [r, c]
    return res
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <bits/stdc++.h>
using namespace std;

int l2_ceil(int x) {
    assert(x > 0);
    int r = (x & (x-1)) != 0;
    while (x >>= 1) ++r;
    return r;
}

struct node {
    int v, s, e, lazy;
};

using tree = vector<node>;

int mk_node(vector<node>& t, const vector<int>& l, int s, int e, int n) {
    if (s == e) {
        return (t[n] = {l[s], s, s, 0}).v;
    }

    int m = (s + e) / 2;
    return (t[n] = {max(mk_node(t, l, s, m, 2*n), mk_node(t, l, m+1, e, 2*n+1)), s, e}).v;
}

tree mk_tree(const vector<int>& l) {
    vector<node> r(1 << (l2_ceil(l.size()) + 1));
    mk_node(r, l, 0, l.size() - 1, 1);
    return r;
}

void add_node(vector<node>& t, int s, int e, int x, int k) {
    auto& n = t[k];
    if (s <= n.s && n.e <= e) {
        n.lazy += x;
        return;
    }
    if (n.e < s || e < n.s) return;

    add_node(t, s, e, x, 2*k);
    add_node(t, s, e, x, 2*k+1);
    n.v = max(t[2*k].v + t[2*k].lazy, t[2*k+1].v + t[2*k+1].lazy);
}

int query_node(vector<node>& t, int s, int e, int k) {
    auto& n = t[k];
    if (s <= n.s && n.e <= e) return n.v + n.lazy;
    if (n.e < s || e < n.s) return numeric_limits<int>::min();

    if (n.lazy) {
        n.v += n.lazy;
        add_node(t, n.s, n.e, n.lazy, 2*k);
        add_node(t, n.s, n.e, n.lazy, 2*k+1);
        n.lazy = 0;
    }
    return max(query_node(t, s, e, 2*k), query_node(t, s, e, 2*k+1));
}

int query(tree& t, int s, int e) {
    return query_node(t, s, e, 1);
}

void add(tree& t, int i, int x) {
    add_node(t, i, i, x, 1);
}

void add_range(tree& t, int s, int e, int x) {
    add_node(t, s, e, x, 1);
}

struct task {
    int d, m, i;
};

int main() {
    int T; cin >> T;
    vector<task> ts;
    for (int i = 0; i < T; ++i) {
        task t{0,0,i};
        cin >> t.d >> t.m;
        ts.push_back(t);
    }
    sort(begin(ts), end(ts), [](auto& t1, auto& t2) { return t1.d < t2.d; });
    vector<int> ixs(T);
    for (int i = 0; i < T; ++i) {
        ixs[ts[i].i] = i;
    }
    vector<int> over(T);
    for (int i = 0; i < T; ++i) {
        over[i] = -ts[i].d;
    }
    auto tr = mk_tree(over);
    for (int i = 0; i < T; ++i) {
        auto j = ixs[i];
        auto t = ts[j];
        add_range(tr, j, T-1, t.m);
        cout << max(0, query(tr, 0, T-1)) << endl;
    }
}