๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.63K subscribers
5.61K photos
3 videos
95 files
10.6K 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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll solve(ll n)
{
    string s="";
    ll mod=1e9+7;
    bool f=0;
    for(ll i=0;i<n;i++)
    {
        if(f==0) {s+='0'; f=1;}
        else {s+='1'; f=0;}
    }
    //cout<<s<<endl;
    ll dp[n+1][2];
    for(ll i=0;i<=n;i++)
     {
        dp[i][0]=0;
        dp[i][1]=0;
     } 

    for(ll i=1;i<=n;i++)
    {
        if(s[i-1]=='1')
        {
            dp[i][1]=(dp[i][1]+dp[i-1][0]+dp[i-1][1]+1)%mod;
            dp[i][0]=(dp[i][0]+dp[i-1][0])%mod;
        }
        else
        {
            dp[i][0]=(dp[i][0]+dp[i-1][1]+dp[i-1][0]+1)%mod;
            dp[i][1]=(dp[i][1]+dp[i-1][1])%mod;
        }
    }
    return (dp[n][0]+dp[n][1])%mod;
}
signed main()
{
    ll n; cin>>n;
    cout<<solve(n);
    return 0;
}


Consistent Data โœ…
class Solution {
    public int wateringPlants(int[] plants, int capacity) {
        int ans = 0;
        int vol = capacity;

        for (int i = 0; i < plants.length; i++) {
            int cur = plants[i];
            boolean isEnoughWater = cur <= vol;
            ans += (isEnoughWater ? 0 : 2) * i + 1;
            vol = (isEnoughWater ? vol : capacity) - cur;
        }

        return ans;
    }
}

Watering plants โœ…
โค1
willy Edge   :).                                                                                        def maxProfit(N, K, cost, sell):
    A = sorted(zip(cost, sell))
    profit = 0
    for a, b in A:
        if b > a and a <= K + profit:
            profit += (b - a)
    return profit

Profits โœ…
#include <bits/stdc++.h>
using namespace std;

int solve(int arr[], int n){

  int pos[n], p = 0;

  for(int i=0;i<n;i++){
    if(arr[i] == 1){
      pos[p] = i + 1;
      p++;
    }
  }

  if(p == 0) return 0;

  int res = 1;
  for(int i=0;i<p-1;i++){
    res *= pos[i+1]-pos[i];
  }
  return res;
}

One block โœ…
๐Ÿ‘3
def Resource(A, B, C):
    same_type_systems = (A // 3) + (B // 3) + (C // 3)
    remaining_A = A % 3
    remaining_B = B % 3
    remaining_C = C % 3
    different_type_systems = min(A, B, C)
    remaining_A -= different_type_systems
    remaining_B -= different_type_systems
    remaining_C -= different_type_systems
    remaining_A = max(0, remaining_A)
    remaining_B = max(0, remaining_B)
    remaining_C = max(0, remaining_C)
    total_systems = same_type_systems + different_type_systems
    leftover_resources = remaining_A + remaining_B + remaining_C
    total_systems += leftover_resources // 3
   
    return total_systems

Resource power โœ…
int Max (int N, int K, vector<int> arr) {
   vector<int> b(N + 1, 0);
    vector<int> c;
    int cnt = 0;
    for (int i = 1; i <= N; ++i) {
        if (arr[i - 1] % 2 == 1) {
            b[i] = 1;
        } else {
            b[i] = -1;
        }
    }
    for (int i = 1; i <= N; ++i) {
        b[i] += b[i - 1];
    }
    for (int i = 1; i < N; ++i) {
        if (b[i] == 0) {
            c.push_back(abs(arr[i] - arr[i - 1]));
        }
    }
    sort(c.begin(), c.end());
    int pt = 0, cost = 0;

    while (pt < c.size() && cost + c[pt] <= K) {
        cost += c[pt];
        ++pt;
    }

    return pt;
}

Max separation โœ…
def modular_exponentiation(base, exponent, mod):
    result = 1
    base = base % mod
    while exponent > 0:
        if exponent & 1:
            result = (result * base) % mod
        exponent = exponent >> 1
        base = (base * base) % mod
    return result

def solve(n):                                                                                                                
    MOD = 10**9 + 7
    base = 3
    result = modular_exponentiation(base, n, MOD)
    return result

Attendance code โœ…
๐Ÿคฉ1
int solve(int n, vector<vector<int>>& rels) {
    vector<vector<int>> g(n);
    vector<int> inD(n, 0);
    for (auto& r : rels) {
        g[r[0] - 1].push_back(r[1] - 1);
        inD[r[1] - 1]++;
    }

    int k = 2;
    int rnds = 0;
    queue<int> q;
    for (int i = 0; i < n; i++) {
        if (inD[i] == 0) {
            q.push(i);
        }
    }

    while (!q.empty()) {
        int sz = q.size();
        rnds += (sz + k - 1) / k;
        for (int i = 0; i < sz; i++) {
            int m = q.front();
            q.pop();
            for (int nxt : g[m]) {
                if (--inD[nxt] == 0) {
                    q.push(nxt);
                }
            }
        }
    }

    return rnds;
}

Family Dinner โœ