๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
const int MOD = 1e9 + 7;
const int MAXN = 1e6;
using namespace std;
vector<bool> sieve() {
    vector<bool> isPrime(MAXN + 1, true);
    isPrime[0] = isPrime[1] = false;
    for (int i = 2; i <= sqrt(MAXN); ++i) {
        if (isPrime[i]) {
            for (int j = i * i; j <= MAXN; j += i) {
                isPrime[j] = false;
            }
        }
    }
    return isPrime;
}

int solve(const string& s) {
    int n = s.size();
    vector<bool> isPrime = sieve();
    vector<int> dp(n + 1, 0);
    dp[0] = 1;

    for (int i = 1; i <= n; ++i) {
        int num = 0;
        for (int j = 1; j <= 6 && i - j >= 0; ++j) {
            num = num + (s[i - j] - '0') * pow(10, j - 1);
            if (s[i - j] != '0' && num <= MAXN && isPrime[num]) {
                dp[i] = (dp[i] + dp[i - j]) % MOD;
            }
        }
    }

    return dp[n];
}

String estee โœ…
long getMaxCost(string s) {
    if (s.find('1') == string::npos) {
        return 0;
    }
    int ind = s.find('1');
    int count = 1;
    int n = s.length();
     long res = 0;
    int prev = ind;
   
    for (int i = ind + 1; i < n; ++i) {
        if (s[i] == '1') {
            if (prev != i - 1) {
                res += (i - prev) * count;
            }
            count += 1;
            prev = i;
        }
    }
   
    if (prev == n - 1) {
        prev = n;
    }
   
    return res + count * (n - prev);
}

Binary Circuit
Estee advisorโœ…
def star_value_finder():
    import sys
    input = sys.stdin.read
    data = input().split()
   
    index = 0
    N = int(data[index])
    index += 1
   
    array = [0] * N
    for i in range(N):
        array[i] = int(data[index])
        index += 1
   
    M = int(data[index])
    index += 1
    Q = int(data[index])
   
    value_count = {}
   
    for i in range(N):
        current_value = array[i]
        for j in range(-Q, Q + 1):
            new_value = current_value + j * M
            if new_value in value_count:
                value_count[new_value] += 1
            else:
                value_count[new_value] = 1
   
    max_count = 0
    for count in value_count.values():
        if count > max_count:
            max_count = count
   
    print(max_count)

star_value_finder()


// Mini orange 2nd
public int candy(int[] ratings) {
    final int n = ratings.length;

    int ans = 0;
    int[] l = new int[n];
    int[] r = new int[n];
    Arrays.fill(l, 1);
    Arrays.fill(r, 1);

    for (int i = 1; i < n; ++i)
      if (ratings[i] > ratings[i - 1])
        l[i] = l[i - 1] + 1;

    for (int i = n - 2; i >= 0; --i)
      if (ratings[i] > ratings[i + 1])
        r[i] = r[i + 1] + 1;

    for (int i = 0; i < n; ++i)
      ans += Math.max(l[i], r[i]);

    return ans;
  }


//MIni orange 3rd
#include <bits/stdc++.h>
using namespace std;

typedef long long lli;

const lli mod = 1000007;

const int mx = 1000000;
const int S = sqrt(mx) + 1;
int prime[mx], np = 0;
bool isnp[mx + 10];

// Sieve of Eratosthenes to find all primes up to mx
void siv(void) {
    int i, j, k;
    np = 0;
    isnp[1] = isnp[0] = true;
    prime[np++] = 2;
    for (i = 3; i <= S; i += 2)
        if (!isnp[i])
            for (prime[np++] = i, j = i * i, k = (i << 1); j <= mx; j += k)
                isnp[j] = true;
    for (; i <= mx; i += 2)
        if (!isnp[i])
            prime[np++] = i;
}

// Function to find the power of prime p in n!
lli pinf(int p, int n) {
    int ans = 0;
    while (n) {
        ans += (n / p);
        n /= p;
    }
    return ans;
}

// Function to find the number of divisors of (n!)^2
lli ndivfact2(int n) {
    int i = 0;
    lli ans = 1;
    while (prime[i] <= n) {
        ans *= (pinf(prime[i], n) * 2) + 1;
        ans %= mod;
        i++;
    }
    return ans;
}

int main() {
    siv();
    int n;
    cin >> n;
    cout << ndivfact2(n) << endl;
    return 0;
}

Modulo arithmetic equation
Estee advisorโœ…
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int minTrucks(vector<int>& boulders, int truckCapacity) {
    vector<int> b = boulders;
    int c = truckCapacity;
    sort(b.begin(), b.end());
    int l = 0, r = b.size() - 1, t = 0;
    while (l <= r) {
        if (b[l] + b[r] <= c) {
            l++;
        }
        r--;
        t++;
    }
    return t;
}
๐Ÿ‘3
#include <vector>
#include <utility>
#include <map>
#include <algorithm>

int deleteProducts(vector<int> ids, int m) {
    vector<pair<int, int>> vp;
    map<int, int> mp;

    for (int x : ids) {
        mp[x]++;
    }

    for (auto it : mp) {
        vp.push_back({it.second, it.first});
    }

    sort(vp.begin(), vp.end());

    int cnt = mp.size();
    for (auto it : vp) {
        if (m >= it.first) {
            m -= it.first;
            cnt--;
        } else {
            break;
        }
    }

    return cnt;
}.

SMART SALE
๐Ÿ‘1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#define MOD 1000000007
using namespace std;
vector<long long> precompute(int max_n) {
    vector<long long> dp(max_n + 1, 0);
    dp[2] = 1;
    if (max_n > 2) dp[3] = 2;
    for (int n = 4; n <= max_n; ++n) {
        dp[n] = (dp[n-1] + dp[n-2]) % MOD;
        dp[n] = (dp[n] + (n - 2)) % MOD;
    }
   
    return dp;
}
int main() {
    int T;
    cin >> T;
    vector<int> queries(T);
    int max_n = 0;
   
    for (int i = 0; i < T; ++i) {
        cin >> queries[i];
        if (queries[i] > max_n) {
            max_n = queries[i];
        }
    }
    vector<long long> dp = precompute(max_n);
    for (int i = 0; i < T; ++i) {
        cout << dp[queries[i]] << endl;
    }
    return 0;
}
#include <iostream> 
#include <vector>

using namespace std;

void printPascalTriangle(int numRows) {
    if (numRows < 1 || numRows > 30) {
        cout << "Invalid number of rows. Please enter a value between 1 and 30." << endl;
        return;
    }

    vector<vector<int>> triangle(numRows);

    for (int i = 0; i < numRows; i++) {
        triangle[i].resize(i + 1);
        triangle[i][0] = triangle[i][i] = 1;

        for (int j = 1; j < i; j++) {
            triangle[i][j] = triangle[i - 1][j - 1] + triangle[i - 1][j];
        }
    }
    for (int i = 0; i < numRows; i++) {
        for (int j = 0; j < i; j++) {
            cout << triangle[i][j] << " ";
        }
        cout << "1" << endl;
    }
}

int main() {
    int numRows;
    cout << "Enter the number of rows for the Pascal Triangle (1-30): ";
    cin >> numRows;
    printPascalTriangle(numRows);
    return 0;
}


Pattern Ques
๐Ÿ‘1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>
using namespace std;
vector<int> applyRule(const vector<int>& P) {
    int n = P.size();
    vector<int> newP(n);
    for (int i = 0; i < n; ++i) {
        newP[i] = P[P[i] - 1];
    }
    return newP;
}
bool isStable(const vector<int>& P) {
    for (int i = 0; i < P.size(); ++i) {
        if (P[i] != i + 1) return false;
    }
    return true;
}
int solve(vector<int>& P) {
    unordered_set<string> seen;
    int time = 0;
    while (true) {
        if (isStable(P)) return time;
        string key = "";
        for (int x : P) key += to_string(x) + ",";
        if (seen.count(key)) return -1;
        seen.insert(key);
        P = applyRule(P);
        ++time;
    }
    return -1;
}
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <vector>
#include <unordered_map>
#include <iostream>

using namespace std;

int getMinTransactions(int n, vector<vector<int>>& debt) {
    unordered_map<int, int> balance
    for (const auto& d : debt) {
        balance[d[0]] -= d[2];
        balance[d[1]] += d[2];
    }
   
    vector<int> transactions;
    for (const auto& entry : balance) {
        if (entry.second != 0) {
            transactions.push_back(entry.second);
        }
    }

    int count = 0;
    int i = 0, j = transactions.size() - 1;
    while (i < j) {
        if (transactions[i] + transactions[j] == 0) {
            count++;
            i++;
            j--;
        } else if (transactions[i] + transactions[j] > 0) {
            transactions[i] += transactions[j];
            j--;
            count++;
        } else {
            transactions[j] += transactions[i];
            i++;
            count++;
        }
    }
    return count;
}

Meesho โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 400;
int grid[MAXN][MAXN];
int dp[MAXN][MAXN][2];
int n, m;
int dfs(int row, int col, bool doubled) {
    if (row >= n || col >= m) return 0;
    if (dp[row][col][doubled] != -1) return dp[row][col][doubled];
   
    int qr = grid[row][col];
    int maxQR = qr + max(dfs(row + 1, col, doubled), dfs(row, col + 1, doubled));

    if (!doubled) {
        maxQR = max(maxQR, qr * 2 + max(dfs(row + 1, col, true), dfs(row, col + 1, true)));
    }
    return dp[row][col][doubled] = maxQR;
}
int main() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> grid[i][j];
        }
    }
    memset(dp, -1, sizeof(dp));
    int result = dfs(0, 0, false);
    cout << result << endl;
   
    return 0;
}.  

//PHONE PE 2 โœ…
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            String str = sc.next();
            String s = "";
            HashMap<Character, Character> map = new HashMap<>();
            int c = 0;

            for (int i = 0; i < n; i++) {
                if (map.containsKey(str.charAt(i))) {
                    s += map.get(str.charAt(i));
                } else {
                    s += (char) (c + '0');
                    map.put(str.charAt(i), (char) (c + '0'));
                    c++;
                }
            }

            int ans1=helper(s, 1, "0", map.size());
            int ans2=helper(s, 1, "1", map.size());
            System.out.println(ans1+ans2);
    }

    public static int helper(String s, int i, String tmp, int val) {
        if (i == val) {
            if (check(s, tmp)) return 1;
            return 0;
        }
        int ans=0;
        ans+=helper(s, i + 1, tmp + "0", val);
        ans+=helper(s, i + 1, tmp + "1", val);
        return ans;
    }

    public static boolean check(String a, String b) {
        int n = a.length();
        int tmp = 0;
        for (int i = 0; i < n; i++) {
            int c = a.charAt(i) - '0';
            tmp += (b.charAt(c) == '0') ? -1 : 1;
            if (tmp < 0) return false;
        }
        return (tmp == 0);
    }
}
VALID SEQUENCES IVP