๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.63K subscribers
5.6K 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
string changeCase(string s, int n)
{
    int n = s.size();
    string ans = "";
    if (n == 1)
    {
        for (int i = 0; i < n; i++)
        {
            int a = 0;
            if (s[i] == ' ')
                a = 1;
            else if (a == 1)
                ans += toupper(s[i]);
            else
                ans += s[i];
        }
    }
    else if (n == 2)
    {
        for (int i = 0; i < n; i++)
        {
            int a = 0;
            if (s[i] == ' ')
                ans += '-';
            else
                ans += s[i];
        }
    }
    else if (n == 3)
    {
        for (int i = 0; i < n; i++)
        {
            int a = 0;
            if (s[i] == ' ')
                ans += '_';
            else
                ans += s[i];
        }
    }
    else if (n == 4)
    {
        ans += toupper(s[0]);
        for (int i = 1; i < n; i++)
        {
            int a = 0;
            if (s[i] == ' ')
                a = 1;
            else if (a == 1)
                ans += toupper(s[i]);
            else
                ans += s[i];
        }
    }
    return ans;
}

Case Styling
IBM C++โœ…
๐Ÿ‘1
int findMaxmumGreyness(vector<string> grid)
{
    int n = grid.size();
    int m = grid[0].length();
    vector<int> one_row(n, 0);
    vector<int> one_col(m, 0);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (grid[i][j] == '1')
            {
                one_row[i]++;
                one_col[j]++;
            }
        }
    }
    int ans = -1e9;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            int ans2 = one_row[i] + one_col[j] - (n + m - one_row[i] - one_col[j]);
            ans = max(ans, ans2);
        }
    }
    return ans;
}

Amazon SDE1
C++โœ…
๐Ÿ‘2
// Infosys
//Given Array A having N integers and divisor K
int morethanNbyK(vector<int> arr, int n, int k)
{
    int x = n / k;
    int ans = 0;
    unordered_map<int, int> freq;
    for (auto i : arr)
        freq[i]++;
    for (auto i : freq)
    {
        if (i.second > x)
        {
            ans += i.first;
        }
    }
    return ans;
}

C++โœ…
๐Ÿ‘1
// Infosys
// N flowers on a Recatangular pana
int ans = 100000000;
void solve(vector<int> a, int n, int k, int index, int sum,
           int maxsum)
{
    if (k == 1)
    {
        maxsum = max(maxsum, sum);
        sum = 0;
        for (int i = index; i < n; i++)
        {
            sum += a[i];
        }
        maxsum = max(maxsum, sum);
        ans = min(ans, maxsum);
        return;
    }
    sum = 0;
    for (int i = index; i < n; i++)
    {
        sum += a[i];
        maxsum = max(maxsum, sum);
        solve(a, n, k - 1, i + 1, sum, maxsum);
    }
}
int GetMaxBeauty(int N, int K, vector<int> A)
{

    solve(A, N, K, 0, 0, 0);
    return ans;
}

infosys-SP-DSP C++โœ…
๐Ÿ‘1
You are given a rooted tree of N vertices and an array A of N integers A[i] is the parent of the vertex (i+1 or 0 if the vertex (i+1) is the root.
For each vertex V from 1 to N, the answer K is the total number of subsets of vertices with the LCA (lowest common ancestor) equal to V Since the of K can be large calculate it modulo 10 ^ 9 + 7
Let there be an integer array Res where Res[i] contains the answer for (I + 1)th  vertex, Find the array Res
Notes:
โ€ข The lowest common ancestor (LCA) is defined for X nodes A1, A2,.... Ax as the lowest node in the tree that has all A1 A2..... Ax as descendants (where we allow a node to be a descendant of itself)

Input Formate
The first line contains an integer N denoting the number of elements in A
Each line 1 of the N subsequent lines (where 0<=i<N) contains an integer
describing All It is given that A[i] denotes the parent of the vertex (i+1) or 0
If the vertex (i+1) is the root

const int N = 100005;
const int MOD = 1e9 + 7;
int  a[N], dp[N], res[N];
vector<int> g[N];
void dfs(int u) {
    dp[u] = 1;
    for (int v : g[u]) {
        dfs(v);
        dp[u] = 1ll * dp[u] * (dp[v] + 1) % MOD;
    }
    res[u] = (1ll * dp[u] * (1 << g[u].size()) - 1 + MOD) % MOD;
}

vector<int> functionName(int n,vector<int>A)
{
    g=A;
    dfs(1);
    return res;
}
  
Language c++โœ…
Infosys
๐Ÿ‘4
You are given Q queries, Each query contains a number N=Quer[i] denoting the ith query.
You have to find M such that:
1 <= M <= N
M|M+1|....| N is as maximum as possible where | is the OR bitwise operation.
M is as maximum as possible.
The answer to this query is the value of M.
Find the sum of answers to all queries modulo 109+7
Note:
A bitwise OR is a binary operation that takes two-bit patterns of equal length and performs the logical inclusive OR operation on each pair of corresponding bits. The result in each position is 0 if both bits are 0, while otherwise, the result is 1.
For example, 0101 (decimal 5) OR 0011 (decimal 3) =0111(decimal 7 )

Input formate:
The first line contains an integer, Q, denoting the number of elements in quer
Each line i of the Q subsequent lines (where 0 <= 1 < Q ) contains an integer describing Quer[i]

const int mod = 1e9 + 7;

int f(int N) {
    return (1 << (bitset<32>(N).count() - 1)) - 1;
}
int solve(int Q,vector<int>Quer)
{
    
    int ans = 0;
    for(int i=0;i<Q;i++)
       
        ans += f(Quer[i]);
        ans %= mod;
    }
    return ans;
}
Language c++โœ…
Infosys
given an array A of size N.

You are allowed to choose at most one pair of elements such that distance (defined as the difference of their indices) is at most K and swap them.

Find the smallest lexicographical array possible after

Notes:

An array x is lexicographically smaller than an array y if there exists an index i such that xi <y i1 and x_{j} = y_{j} for all 0 <= j < i . Less formally, at the first index i in which they differ xi < yi
Input Formats@gman

The First-line contains Integers N Ea an integer, N, denoting the line i of the N subsequent lines (where describing A[i]. of elements in A. N) contains an integer

The next line contains an integer, K, denoting the upper bound on distance of index.

Constraints
Here as all the array values are equal swapping will not change the final result,

Here A=[5,4,3,2,11 K we can swap elements at index 0 and index 3 which makes A= [2,4,3,5,1].

Here A=[2,1,1,1,1] K we can swap elements at index 0 and index 3 chat which makes A= [1.1.1.2.11




bool swapped = false;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j <= min(i + K, N - 1); j++) {
            if (A[i] > A[j]) {
                swap(A[i], A[j]);
                swapped = true;
                break;
            }
        }
        if (swapped) break;
    }
    if (!swapped) return A;
    else return A;

C++โœ…
Infosys
๐Ÿ‘1