๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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โœ