๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.57K subscribers
5.58K photos
3 videos
95 files
9.96K 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
ll solve(vector<ll>& a) {
    unordered_map<ll, ll> c;
    ll l = 0, r = 0;
    ll m = 0;
    while (r < a.size()) {
        c[a[r]]++;
        while (c.size() > 2) {
            if (--c[a[l]] == 0) {
                c.erase(a[l]);
            }
            l++;
        }
        m = max(m, r - l + 1);
        r++;
    }
    return m;
}

Longest Subarray โœ…
๐Ÿ‘2
Maruti Suzuki All India Hiring Test:

Role: Assistant Manager

Graduation Year: 2022

Degree: B.Tech / M.Tech

Eligible Branches: Mechanical, Automobile, Civil, Electrical, Electronics, Mechatronics and Tool & Die

Age: 21 to 27 years

Work Experience: 12 to 22 months

Selection Process:
1. Profile Shortlisting
2. Online Test (Technical, Aptitude & Psychometric)
3. Personal Interview (Technical + HR)
4. Offer
5. Medical Test
6. Joining

B.Tech CTC: 10.34 LPA (8.3 LPA - Fixed)
M.Tech CTC: 10.99 LPA (8.85 LPA Fixed)

Location: PAN - India

Apply Link: https://maruti.app.param.ai/jobs/all-india-hiring-ait-2024-btech-and-mtech


Last Date to Apply: 21st April 2024
๐Ÿ‘2
private static double[] calculateMovingAverage(int[] array, int K) {
        double[] smoothedArray = new double[array.length - K + 1];
        double sum = 0;

      
        for (int i = 0; i < K; i++) {
            sum += array[i];
        }

      
        for (int i = 0; i <= array.length - K; i++) {
            if (i > 0) {
              
                sum = sum - array[i - 1] + array[i + K - 1];
            }
            smoothedArray[i] = sum / K;
        }

        return smoothedArray;
    }

Moving Averagesโœ…
๐ŸŽ‰1
#include <iostream>
#include <vector>

using namespace std;

int divideTerritory(int n, vector<int>& qualities) {
    int totalQuality = 0;
    for (int i = 0; i < n; ++i) {
        totalQuality += qualities[i];
    }
    if (totalQuality % 3 != 0) {
        return 0;
    }
   
    int targetQuality = totalQuality / 3;
    vector<int> prefixSums(n, 0);
    int currentSum = 0;
    int count = 0;
   
    for (int i = 0; i < n; ++i) {
        currentSum += qualities[i];
        prefixSums[i] = currentSum;
    }
   
    for (int i = 0; i < n - 2; ++i) {
        if (prefixSums[i] == targetQuality) {
            for (int j = i + 1; j < n - 1; ++j) {
                if (prefixSums[j] - prefixSums[i] == targetQuality && prefixSums.back() - prefixSums[j] == targetQuality) {
                    count++;
                }
            }
        }
    }
   
    return count;
}

Three little pigs โœ…
#include <iostream>
#include <string>
#include <stack>
using namespace std;

int solve(const string& s) {
    stack<char> stk;
    int insertions = 0;
   
    for (char c : s) {
        if (c == '(') {
            stk.push(c);
        } else {
            if (stk.empty()) {
                insertions++;
            } else {
                stk.pop();
            }
        }
    }
   
    insertions += stk.size();
    return insertions;
}

The String โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
#include <iostream> #include <vector> using namespace std; int divideTerritory(int n, vector<int>& qualities) {     int totalQuality = 0;     for (int i = 0; i < n; ++i) {         totalQuality += qualities[i];     }     if (totalQuality % 3 != 0) {        โ€ฆ
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[110][110];
ll currsumdp[110][110];
ll sum=0;
ll helper(ll i,ll n,ll part,ll curr,ll totsum,vector<ll>&a)
{
    if(i!=n and part==4) return 0;
    if(i==n) return(part==4)?1:0;
    if(currsumdp[i][part]) return dp[i][part];
    curr+=a[i];
    currsumdp[i][part]=1;
   return dp[i][part]=helper(i+1,n,part,curr,totsum,a)+((curr==(totsum/3)*part)?helper(i+1,n,part+1,curr,totsum,a):0);

}
ll solve(vector<ll>&a)
{
    ll n=a.size();
    for(auto it:a) sum+=it;
    if(n<3 or sum%3) return 0;
    memset(dp,-1,sizeof(dp));
    return helper(0,n,1,0,sum,a);
}
signed main() {
    ll n; cin>>n;
    vector<ll>a(n);
    for(ll i=0;i<n;i++) cin>>a[i];
    cout<<solve(a);
    return 0;
}


Three little pigs โœ…
๐Ÿ‘Ž3๐Ÿ‘2
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll solve(vector<char>&a)
{
    stack<char>st;
    ll n=a.size();
    ll i=0;
    while(i<n)
    {
        if(a[i]=='P')
        {
            i++;
            st.push(a[i]);
        }
        else if(a[i]=='B')
        {
            i++;
            if(st.top()==a[i]) st.pop();
            else break;
        }
        i++;
    }
    if(st.empty()) return -1;
    return st.size()+1;
}
signed main() {
    
     string s;
     getline(cin,s);
     vector<char>a;
     for(auto it:s)
        if(it!=' ') a.push_back(it);
     cout<<solve(a);

    return 0;
}

Flipkart โœ…
int countSetBits(int num) {
    return __builtin_popcount(num);
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        int N, K;
        cin >> N >> K;
        vector<int> array(N);
        for (int i = 0; i < N; i++) {
            cin >> array[i];
        }
       
        int validSubsetCount = 0;
        int maxSubsetMask = (1 << N) - 1;
        for (int mask = 0; mask <= maxSubsetMask; mask++) {
            int subsetSum = 0;
            for (int j = 0; j < N; j++) {
                if (mask & (1 << j)) {
                    subsetSum += array[j];
                }
            }
            if (countSetBits(subsetSum) == K) {
                validSubsetCount++;
            }
        }
       
        cout << validSubsetCount << endl;
    }
    return 0;
}

Flipkart โœ…
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int maxBagsFilled(int weight, int s1, int s2, int s3) {
    vector<int> dp(weight + 1, -1e9);
    dp[0] = 0;

    vector<int> sizes = {s1, s2, s3};

    for (int i = 1; i <= weight; i++) {
        for (int size : sizes) {
            if (i >= size && dp[i - size] != -1e9) {
                dp[i] = max(dp[i], dp[i - size] + 1);
            }
        }
    }

    return dp[weight] > 0 ? dp[weight] : 0;
}

int main() {
    int weight;
    int s1, s2, s3;
   
    cin >> weight;
    cin >> s1 >> s2 >> s3;
   
    cout << maxBagsFilled(weight, s1, s2, s3) << endl;
   
    return 0;
}

Flipkart โœ…
#include <bits/stdc++.h>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }

    vector<vector<int>> jump_count(N + 1, vector<int>(N + 1, 0));
    vector<bool> visited(N + 1, false);
    int total_distance = 0;

    for (int start = 1; start <= N; ++start) {
        if (visited[start]) continue;

        vector<int> trace;
        int current = start;
        while (!visited[current]) {
            visited[current] = true;
            trace.push_back(current);
            current = A[current];
        }

        int cycle_index = find(trace.begin(), trace.end(), current) - trace.begin();
        int cycle_length = trace.size() - cycle_index;

        for (int i = 0; i < trace.size(); ++i) {
            for (int j = i; j < trace.size(); ++j) {
                jump_count[trace[i]][trace[j]] = j - i;
                if (i != j) {
                    jump_count[trace[j]][trace[i]] = trace.size() - (j - i);
                }
            }
        }
    }

    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            total_distance += jump_count[i][j];
        }
    }

    cout << total_distance << endl;
    return 0;
}

Maze Telepoters
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll> count(ll k,vector<ll>& a) {
    vector<ll> prime;
    for (ll i=2;i<=sqrt(k);i++)
    {
        if (k%i==0)
        {
            prime.push_back(i);
            while (k%i==0) k/=i;   
        }
    }
    if (k>1)prime.push_back(k);
    vector<ll>counts(prime.size(),0);
    for (auto num:a)
    {
        for (ll i=0;i<prime.size();i++)
        {
            ll factor=prime[i];
            while (num%factor==0)
            {
                counts[i]++;
                num/=factor;
            }
        }
    }
    return counts;
}
ll helper(vector<ll>a,ll k)
{
     vector<ll>factorCounts=count(k,a);
    return factorCounts.empty()?0:*min_element(factorCounts.begin(), factorCounts.end());
}
signed main() {
    ll n, k; cin>>n>>k;
    vector<ll>a(n);
    for(ll i=0;i<n;i++) cin>>a[i];
    cout<<min(n,helper(a,k));
    return 0;
}


K-divisible number โœ…
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

int solve(int N, vector<int>& a, int K) {
    unordered_map<int, int> freq;

    for (int i = 0; i < N / 2; ++i) {
        int diff = abs(a[i] - a[N - 1 - i]);
        if (diff > K) {
            diff = K;
        }
        freq[diff]++;
    }

    int max_freq = 0;
    for (const auto& kvp : freq) {
        max_freq = max(max_freq, kvp.second);
    }

    int moves = N / 2 - max_freq;

    return moves;
}

Balanced Array โœ