ru
Feedback
Coding | EXAMS | IBM ACCENTURE | VIRTUSA | IBM | AMAZON | TCS | EPAM | WILEY EDGE | TECH MAHINDRA | JPMORGAN | HCL | WIPRO

Coding | EXAMS | IBM ACCENTURE | VIRTUSA | IBM | AMAZON | TCS | EPAM | WILEY EDGE | TECH MAHINDRA | JPMORGAN | HCL | WIPRO

Открыть в Telegram

Main channel https://t.me/Coding_000 Contact Admin 👉 @ILOVEU_143 for booking your exam slots Web- https://coding000.github.io/Projects/ 💯% clearance in any placement exams OffCampus -https://t.me/Offcampus_000 Discussion- https://t.me/exams_discussion

Больше
3 368
Подписчики
-324 часа
-197 дней
-5030 день
Архив постов
Colourd ball Kth palindrome String container Play with stacks Perfectly even Divisible string

Colourd ball Kth palindrome String container Play with stacks Perfectly even Divisible string Share @coding_000❤️✅
+6
Colourd ball Kth palindrome String container Play with stacks Perfectly even Divisible string Share @coding_000❤️✅

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

vector<int> A, P;
vector<vector<int>> tree;
vector<int> ranges;
long long result = 0;

void dfs(int node, int parent, set<int>& values) {
    values.insert(A[node]);
    set<int> child_values;
    int num_ranges = 1, last = -1;

    for (int val : values) {
        if (last != -1 && val != last + 1) num_ranges++;
        last = val;
    }

    ranges[node] = num_ranges;

    for (int child : tree[node]) {
        if (child == parent) continue;
        child_values = values;
        dfs(child, node, child_values);
    }

    result = (result + ranges[node]) % MOD;
}

int main() {
    int N;
    cin >> N;

    A.resize(N);
    P.resize(N);
    tree.resize(N);
    ranges.resize(N);

    for (int i = 0; i < N; ++i) {
        cin >> P[i];
        if (i > 0) tree[P[i]].push_back(i);
    }

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

    set<int> values;
    dfs(0, -1, values);

    cout << result << endl;
    return 0;
}
path coverage range ✅

import java.util.*; class Main {   public static void main (String[] args) {     Scanner sc=new Scanner(System.in);     int n=sc.nextInt(),i;     TreeMap<Long,Integer> map=new TreeMap<>();     long dp[]=new long[n];     long r[]=new long[n];     long h[]=new long[n];     long mod=(long)1e9+7;     for(i=0;i<n;i++) r[i]=sc.nextLong();     for(i=0;i<n;i++) h[i]=sc.nextLong();     for(i=0;i<n;i++){         long volume=(h[i]*r[i]*r[i])%mod;         Long low=map.floorKey(volume);         if(low!=null) dp[i]=(dp[i]+dp[map.get(low)]+volume)%mod;         else dp[i]=(dp[i]+volume)%mod;         map.put(volume,i);     }     long max=0;     for(long it:dp) max=Math.max(max,it);     System.out.println(max);   } } Increasing mex counting ✅

#include <bits/stdc++.h> using namespace std; int minimumCost(int N, vector<int> A, vector<vector<int>> Cost) {     int minCost = INT_MAX;     vector<int> perm(N);     iota(perm.begin(), perm.end(), 1);     do {         bool valid = true;         for (int i = 0; i < N; ++i) {             if (perm[i] > A[i]) {                 valid = false;                 break;             } else if (perm[i] < A[i]) {                 break;             }         }         if (valid) {             int cost = 0;             for (int i = 0; i < N; ++i) {                 cost += Cost[i][perm[i] - 1];             }             minCost = min(minCost, cost);         }     } while (next_permutation(perm.begin(), perm.end()));     return minCost; } int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int N;     cin >> N;     vector<int> A(N);     for (int i = 0; i < N; ++i) {         cin >> A[i];     }     vector<vector<int>> Cost(N, vector<int>(N));     for (int i = 0; i < N; ++i) {         for (int j = 0; j < N; ++j) {             cin >> Cost[i][j];         }     }     cout << minimumCost(N, A, Cost) << endl;     return 0; } Cheapest permutation ✅

Guys pls wait i will try to send...asap maximum answers....❤️ kerp sharing  @coding_000✅ Check once above 👆👆👆

#include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; int main() {     ll n, i, j;     cin >> n;     ll a[n];     for(i=0; i<n; i++)     {         cin >> a[i];     }         ll maxi = 0;     i=0;     while(i<n-1)     {         ll curr=0;         for(j=i; j<n-1; j++)         {             int diff = a[j+1]-a[j];             if(diff<0)             {                 break;             }             else if((diff & (diff-1)) == 0 || diff==0)             {                 curr++;             }             else             {                 break;             }         }         i=j+1;         maxi = max(maxi, curr+1);     }     if(n==1) maxi=1;     cout<<maxi<<'\n';     return 0; } Yet another lies ✅ Infosys

#include <bits/stdc++.h>
#define ll long long  
using namespace std;
ll mod=1e9+7;
ll C(vector<ll>&a,ll n)
{

    ll count=0;
    for(ll i=0;i<n-1;i++) 
    {
        if(((a[i]*a[i+1])-(a[i]+a[i+1]))%2==0) count++;
    }
    return count;
}

void generate(ll n,ll m,ll k,vector<ll>&current,ll&count) 
{
    if (current.size()==n) 
    {
        if (C(current,n)==k) 
        {
            count=(count+1)%mod;
        }
        return;
    }
    for (ll i=1;i<=m;i++) 
    {
        current.push_back(i);
        generate(n,m,k,current,count);
        current.pop_back();
    }
}
ll solve(ll n,ll m,ll k)
{
    vector<ll>current;
    ll count=0;
    generate(n,m,k,current,count);
    return count%mod;
}
signed main() 
{
    ll n,m,k; cin>>n>>m>>k;
    cout<<solve(n,m,k);
    return 0;
}
Perfectly even ✅

#include <bits/stdc++.h>
#define ll long long  
using namespace std;
ll mod(ll x,ll mod)
{
    if(x<mod) return 0;
    return x%mod;
}
bool check(ll l,ll r,ll k,vector<ll>&a)
{
    unordered_map<ll,ll>mpp;
    for(ll i=l;i<=r;i++) mpp[i]++;
    for(auto it:mpp)
    {
       if(it.second!=k) return false;
    }
    return true;
}
ll solve(ll n,ll k,vector<ll>&a,ll q,vector<vector<ll>>&queries)
{
    if(k==1)
    {
        ll sum=0;
        for(ll i=1;i<=q;i++) sum+=i;
        return sum;
    }
    vector<ll>p(q);
    ll t=0,tt=0;
    ll L,R;
    for(ll i=0;i<q;i++)
    {    
        L=mod((t+queries[i][0]),n)+1;
        R=mod((tt+queries[i][1]),n)+1;
        t=L;
        tt=R;
        if(check(L,R,k,a)) p[i]=i+1;
    }
    ll sum=0;
    ll m=1e9+7;
    for(auto  it:p) sum=(sum+it)%m;
    return sum%m;
}
signed main() 
{
    ll n,k; cin>>n>>k;
    vector<ll>a(n);
    for(ll i=0;i<n;i++) cin>>a[i];
    ll q; cin>>q;
    ll two; cin>>two;
    vector<vector<ll>>queries(q,vector<ll>(2));
    for(ll i=0;i<q;i++)
    {
        ll x,y; cin>>x>>y;
        queries[i][0]=x;
        queries[i][1]=y;
        //cout<<x<<" "<<y<<endl;
    }
    cout<<solve(n,k,a,q,queries);
    return 0;
}
K occurance ✅

#include <bits/stdc++.h> #define ll long long  using namespace std; ll mod(ll x, ll m) {     if (x < m) return 0;     return x % m; } bool check(ll l, ll r, ll k, vector<ll>& a) {     unordered_map<ll, ll> mp;     for (ll i = l; i <= r; i++) mp[i]++;     for (auto it : mp) {         if (it.second != k) return false;     }     return true; } ll sumQueries(ll q) {     ll sum = 0;     for (ll i = 1; i <= q; i++) sum += i;     return sum; } vector<ll> processQueries(ll n, ll q, vector<vector<ll>>& queries) {     vector<ll> res(q);     ll t = 0, tt = 0;     ll L, R;     for (ll i = 0; i < q; i++) {         L = mod((t + queries[i][0]), n) + 1;         R = mod((tt + queries[i][1]), n) + 1;         t = L;         tt = R;         res[i] = {L, R};     }     return res; } ll solve(ll n, ll k, vector<ll>& a, ll q, vector<vector<ll>>& queries) {     if (k == 1) {         return sumQueries(q);     }     vector<ll> p(q);     vector<ll> processedQueries = processQueries(n, q, queries);     ll sum = 0;     ll m = 1e9 + 7;     for (ll i = 0; i < q; i++) {         if (check(processedQueries[i].first, processedQueries[i].second, k, a)) {             p[i] = i + 1;         }         sum = (sum + p[i]) % m;     }     return sum % m; } signed main() {     ll n, k; cin >> n >> k;     vector<ll> a(n);     for (ll i = 0; i < n; i++) cin >> a[i];     ll q; cin >> q;     ll two; cin >> two;     vector<vector<ll>> queries(q, vector<ll>(2));     for (ll i = 0; i < q; i++) {         ll x, y; cin >> x >> y;         queries[i][0] = x;         queries[i][1] = y;     }     cout << solve(n, k, a, q, queries);     return 0; } Online K occurences queries✅ Infosys

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const vector<pair<int, int>> directions = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

int InvasionTime(int N, int M, vector<string>& Q) {
    vector<vector<char>> grid(N, vector<char>(M));
    queue<pair<int, int>> q;
    int enemyCount = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            grid[i][j] = Q[i][j];
            if (grid[i][j] == 'A') {
                q.push({i, j});
            } else if (grid[i][j] == 'E') {
                ++enemyCount;
            }
        }
    }
    if (enemyCount == 0) {
        return 0;
    }

    int time = 0;
    while (!q.empty()) {
        int size = q.size();
        ++time;

        for (int i = 0; i < size; ++i) {
            int x = q.front().first;
            int y = q.front().second;
            q.pop();

            for (const auto& dir : directions) {
                int nx = x + dir.first;
                int ny = y + dir.second;

                if (nx >= 0 && ny >= 0 && nx < N && ny < M && grid[nx][ny] == 'E') {
                    grid[nx][ny] = 'A';
                    q.push({nx, ny});
                    --enemyCount;

                    if (enemyCount == 0) {
                        return time;
                    }
                }
            }
        }
    }

    return -1;
}

int main() {
    int N, M;
    cin >> N >> M;
    cin.ignore(); 

    vector<string> Q(N);
    for (int i = 0; i < N; ++i) {
        getline(cin, Q[i]);
    }

    cout << InvasionTime(N, M, Q) << endl;

    return 0;
}
Army invasion ✅ Infosys

from math import gcd
from collections import defaultdict

def lcm(a, b):
    return abs(a * b) // gcd(a, b)

def find_minimum_subgraph(N, values, edges):

    total_lcm = values[0]
    for i in range(1, N):
        total_lcm = lcm(total_lcm, values[i])
    
    graph = defaultdict(list)
    for u, v in edges:
        graph[u-1].append(v-1)
        graph[v-1].append(u-1)
    
    min_size = N
    subtree_lcm = values.copy()
    
    def dfs(node, parent):
        nonlocal min_size
        size = 1
        current_lcm = values[node]
        
        for child in graph[node]:
            if child != parent:
                child_size, child_lcm = dfs(child, node)
                size += child_size
                current_lcm = lcm(current_lcm, child_lcm)
        
        if current_lcm == total_lcm:
            min_size = min(min_size, size)
            return 0, total_lcm
        
        return size, current_lcm
    
    dfs(0, -1)
    return min_size
tree cutting✅ Infosys

#include <iostream> #include <vector> #include <numeric> #define MOD 1000000007 using namespace std; long long mod_inv(long long x, long long mod) {     long long result = 1;     long long power = mod - 2;     while (power) {         if (power % 2) {             result = result * x % mod;         }         x = x * x % mod;         power /= 2;     }     return result; } vector<long long> factorial(int n, long long mod) {     vector<long long> fact(n + 1, 1);     for (int i = 2; i <= n; ++i) {         fact[i] = fact[i - 1] * i % mod;     }     return fact; } long long binomial_coeff(int n, int k, const vector<long long>& fact, long long mod) {     if (k > n || k < 0) {         return 0;     }     return fact[n] * mod_inv(fact[k], mod) % mod * mod_inv(fact[n - k], mod) % mod; } long long count_ways(int N, int K, const vector<int>& A) {     int sum_A = accumulate(A.begin(), A.end(), 0);     int M = K - sum_A;     vector<long long> fact = factorial(M + N - 1, MOD);     return binomial_coeff(M + N - 1, N - 1, fact, MOD); } int main() {     int N, K;     cin >> N >> K;     vector<int> A(N);     for (int i = 0; i < N; ++i) {         cin >> A[i];     }     cout << count_ways(N, K, A) << endl;     return 0; } Distributing Books

Guys pls wait i will try to send...asap maximum answers....❤️ kerp sharing  @coding_000

Coding | EXAMS | IBM ACCENTURE | VIRTUSA | IBM | AMAZON | TCS | EPAM | WILEY EDGE | TECH MAHINDRA | JPMORGAN | HCL | WIPRO - Статистика и аналитика Telegram-канала @coding_000