๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <string>
using namespace std;
string helper(const string& s, size_t& index) {
    string ans = "";
    int isans = 0;
    while (index < s.length())
    {
        if (isdigit(s[index]))
        {
            isans = isans * 10 + (s[index] - '0');
        } else if (s[index] == '(')
        {
            index++;
            string subResult = helper(s, index);
            for (int i = 0; i < isans; i++)
            {
                ans += subResult;
            }
            isans = 0;
        } else if (s[index] == ')')
        {
            index++;
            return ans;
        } else
        {
            ans += s[index];
        }
        index++;
    }
   
    return ans;
}
string expandString(const string& s) {
    size_t index = 0;
    return helper(s, index);
}
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <string>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
int swapAndCount(string s, string t) {
    int swaps=0;
    int flag=1;
    int n=s.size();
    for(int i=0;i<n;i++){
        if(s[i]==t[i]) continue;
        else if(s[i]<t[i]){
            if(flag) {
                swaps++;
                flag=0;
            }
            if(!flag){
                continue;
            }
        }
        else{
            if(flag){
                flag=0;
            }
            else if(!flag){
                swaps++;
            }
        }
    }
    return swaps;
}
int solution(string S, string T) {
    return min(swapAndCount(S, T),swapAndCount(T, S));
}
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
#include <functional>

long long solve(int N, std::vector<int> from, std::vector<int> to, std::vector<int> weight, int k) {
    std::vector<std::vector<std::pair<int, int>>> adj(N);
    for (int i = 0; i < N - 1; ++i) { // build adj
        adj[from[i]].emplace_back(to[i], weight[i]);
        adj[to[i]].emplace_back(from[i], weight[i]);
    }

    std::function<std::array<long long, 2>(int, int)> dfs = [&](int cur, int parent) {
        std::array<long long, 2> ans{};
        std::vector<long long> take, skip, diff;
        for (auto& [next, w] : adj[cur]) if (parent != next) {
            auto [not_full, full] = dfs(next, cur);
            take.push_back(not_full + w);
            skip.push_back(full);
            diff.push_back(take.back() - skip.back());
        }

        int n = int(diff.size());
        std::ranges::nth_element(diff, diff.begin() + k - 1, std::greater<>());
        ans[0] = std::reduce(diff.begin(), diff.begin() + std::min(k, n)) + std::reduce(skip.begin(), skip.end());
       
        if (n && n >= k) {
            ans[1] = ans[0];
            ans[0] -= *std::min_element(diff.begin(), diff.begin() + k);
        }

        return ans;
    };

    auto ans = dfs(0, -1);
    return std::max(ans[0], ans[1]);
}

Server โœ…
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
   
    int l = 0, r = n - 1;
    while (l < n && a[l] == 0) l++;
    while (r > l && a[r] == 0) r--;

    int ans = 0;
    if ((r - l + 1) % 2 == 0) {
        if (a[l] > a[r]) {
            ans += a[r];
            r--;
        } else {
            ans += a[l];
            l++;
        }
    }

    int sum = 0, c = 1, max1 = 0, sum1 = 0, max2 = 0, sum2 = 0;
    for (int i = l; i <= r; i++) {
        sum += a[i];
        int tmp = c / 2;
        int god = (tmp * (tmp + 1)) + (tmp + 1);
        if (god <= sum && c % 2 == 1) {
            max1 = c;
            sum1 = sum;
        }
        c++;
    }

    c = 1;
    sum = 0;
    for (int i = r; i >= l; i--) {
        sum += a[i];
        int tmp = c / 2;
        int god = (tmp * (tmp + 1)) + (tmp + 1);
        if (god <= sum && c % 2 == 1) {
            max2 = c;
            sum2 = sum;
        }
        c++;
    }

    int max1h = max1 / 2, max2h = max2 / 2;
    int ans1 = (max1h * (max1h + 1)) + (max1h + 1);
    int ans2 = (max2h * (max2h + 1)) + (max2h + 1);
    cout << min(sum - sum1 + sum1 - ans1, sum - sum2 + sum2 - ans2) + ans << endl;

    return 0;
}


//bitonic array โœ…
Onix is hiring for Software Engineers

2024 batch eligibile
Delhi/Hyderabad/Pune/Bangalore
2 sept 2024 is the joining date

Selection Process :
Online Aptitude cum Technical Assessment โ€“ 95 minutes
Two Levels of Technical Interviews
HR Interview

Apply Form : https://forms.gle/sanQ1wiQKkZCN1Ss9
Role: Software development Intern
Company: Thriving Springs
Tech stacks, HTML, CSS
Good to know: Angular, Node.js
Location: Hyderabad
Mode of Work: Work from Office
Working Days: Monday to Friday; (Monday to Thursday - WFO, Friday - WFH)
Stipend - 20K/M
Duration - 6 months
Open Positions - 10
Post Completion of the Internship period, PPO offered from 5 LPA to 7.5 LPA based upon performance evaluation.

Apply here - https://forms.gle/ea47rjtc5ZUjQdrU6
๐Ÿ‘1
typedef long long ll;

pair<ll, ll> largestPowerof2(ll n)
{
ll ans = 0;
for (ll i = 30; i >= 0; i--) {
  if ((1LL << i) & n) {
   ans = i;
   break;
  }
}

ans = min(25LL, ans);
return { ans, 1LL << ans };
}

string solve(ll n)
{
string str = "abcdefghijklmnopqrstuvwxyz";
string ans = "";
while (n) {
  pair<ll, ll> a = largestPowerof2(n);
  ll pw = a.first;
  ll value = a.second;
  ans += str[pw];
  n -= value;
}
return ans;
}


ms task 2 โœ