๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.63K subscribers
5.59K photos
3 videos
95 files
10.2K 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
Need Java Developers (2023-24 Graduates), Dot Net Developers (Open to all Graduates) and Python Developers (2023-24 Graduates) for Fortune Cloud*๐Ÿ’ฅ๐Ÿ’ฅ๐Ÿ’ฅ

Package Details:
1-3 Months Training Period: Stipend- Rs. 10,000 (fixed) + Rs. 5000 (performance -based)
After Training, Salary: Rs. 3.6LPA

Date of Interview: 22.08.2024 @ 09:30 AM sharp.

Venue: B-1, 3rd Floor, Abhinav Apartment, Besides Congress House Rd, Shivajinagar, Pune, Maharashtra- 411005 (Near Rathson Traders, Congress Bhawan).
def proBinary(s):
    n = len(s)
    x = 0
    y = 0
    flip = 0
   
    for i in range(n):
        bit = int(s[i])
        x = (x << 1) | bit
        flip = (flip << 1) | (1 - bit)
   
    y = flip
    return f"{x} {y}"


Texas โœ…
def find_unsorted_subarray_length(nums):
    n = len(nums)

    left = 0
    while left < n - 1 and nums[left] <= nums[left + 1]:
        left += 1

    if left == n - 1:
        return 0

    right = n - 1
    while right > 0 and nums[right] >= nums[right - 1]:
        right -= 1

    min_val = min(nums[left:right + 1])
    max_val = max(nums[left:right + 1])

    while left > 0 and nums[left - 1] > min_val:
        left -= 1

    while right < n - 1 and nums[right + 1] < max_val:
        right += 1

    length = right - left + 1

    return length

nums_input = input()
nums_list = list(map(int, nums_input.split()))

output1 = find_unsorted_subarray_length(nums_list)
print(output1)

Arrange the heights
Apple โœ…
๐Ÿ‘1
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>

using namespace std;
#define ll long long

void solve(string x) {
    ll n = x.size();
    vector<vector<ll>> dp(n, vector<ll>(n, 0));

    for (ll i = 0; i < n; i++) {
        dp[i][i] = 1;
    }

    for (ll k = 1; k < n; k++) {
        for (ll i = 0; i < n - k; i++) {
            ll j = i + k;
            if (x[i] == x[j]) {
                dp[i][j] = 2 + dp[i + 1][j - 1];
            } else {
                dp[i][j] = max(dp[i][j - 1], dp[i + 1][j]);
            }
        }
    }

    ll ans = 0;

    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < n - 1; j++) {
            ans = max(ans, dp[i][j] * dp[j + 1][n - 1]);
        }
    }

    cout << ans;
}

int main() {
    string input;
    cin >> input;

    solve(input);

    return 0;
}

Game of sequence reverse
Apple โœ…
#include <iostream>
#include <string>
using namespace std;
bool isPalindrome(long long n) {
    string s = to_string(n);
    int len = s.length();
    for (int i = 0; i < len / 2; ++i) {
        if (s[i] != s[len - i - 1]) {
            return false;
        }
    }
    return true;
}
long long getNextPalindrome(long long N) {
    while (true) {
        ++N;
        if (isPalindrome(N)) {
            return N;
        }
    }
}
int main() {
    long long N;
    cin >> N;
    long long result = getNextPalindrome(N);
    cout << result;
    return 0;
}

Ascendion โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
def getSeatsAllocation(arr):
    n = len(arr)
    ppl = [[] for i in range(2 * n + 4)]
   
    for i, x in enumerate(arr):
        ppl[x].append(i)

    h = []
    ans = [-1] * n
   
    for pos in range(1, 2 * n + 1):
        for i in ppl[pos]:
            heapq.heappush(h, (-pos, i))
       
        if len(h) > 0:
            ans[heapq.heappop(h)[1]] = pos
   
    return ans

BNY(Intern)โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
import java.util.*;
public class StockPrediction {

    public List<Integer> predict(List<Integer> stockData, List<Integer> queries) {
        List<Integer> result = new ArrayList<>();
        int n = stockData.size();
       
        TreeSet<Integer> treeSet = new TreeSet<>(stockData);
       
        if (treeSet.size() == 1) {
            Collections.fill(result, -1);
            return result;
        }
       
        for (int query : queries) {
            int stockPrice = stockData.get(query - 1);
           
            if (treeSet.first() >= stockPrice) {
                result.add(-1);
                continue;
            }
           
            int nearestDay = -1;
            int left = query - 2;
            int right = query;
            while (left >= 0 || right < n) {
                if (left >= 0 && stockData.get(left) < stockPrice) {
                    nearestDay = left + 1;
                    break;
                }
                if (right < n && stockData.get(right) < stockPrice) {
                    nearestDay = right + 1;
                    break;
                }
                left--;
                right++;
            }
           
            result.add(nearestDay);
        }
       
        return result;
    }


BNY(intern)โœ…
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vll vector<ll>

struct M {
    ll s;
    ll r;
};

bool cmp(M a, M b) {
    return a.r > b.r;
}

ll solve(vll& s, vll& r, ll m) {
    ll n = s.size();
    vector<M> v(n);
    for(ll i=0; i<n; i++) {
        v[i].s = s[i];
        v[i].r = r[i];
    }
    sort(v.begin(), v.end(), cmp);
    priority_queue<ll, vll, greater<ll>> q;
    ll ts = 0, mq = 0;
    for(ll i=0; i<n; i++) {
        ts += v[i].s;
        q.push(v[i].s);
        if(q.size() > m) {
            ts -= q.top();
            q.pop();
        }
        mq = max(mq, ts * v[i].r);
    }
    return mq;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    ll n;
    cin >> n;
    vll s(n), r(n);
    for(ll i=0; i<n; i++) {
        cin >> s[i];
    }
    for(ll i=0; i<n; i++) {
        cin >> r[i];
    }
    ll m;
    cin >> m;
    cout << solve(s, r, m) << endl;
    return 0;
}

BNY (intern) โœ…
๐Ÿ‘1
from collections import defaultdict

def cheapestFare(n_towns, source, destination, max_stops, routes):
    graph = defaultdict(list)
    for start, end, cost in routes:
        graph[start].append((end, cost))
   

    costs = [float('inf')] * n_towns
    costs[source] = 0
   
    for i in range(max_stops + 1):
        new_costs = costs.copy()
        for start in range(n_towns):
            if costs[start] == float('inf'):
                continue
            for end, cost in graph[start]:
                new_costs[end] = min(new_costs[end], costs[start] + cost)
        costs = new_costs
   
    return costs[destination] if costs[destination] != float('inf') else -1

Trip planner
Makemytripโœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <iostream>
#include <vector>
using namespace std;

const int MOD = 1e9 + 7;

int countValidSeries(int n, int m, vector<int>& f) {
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
    if (f[0] == 0) {
        for (int j = 1; j <= m; ++j) {
            dp[1][j] = 1;
        }
    } else {
        dp[1][f[0]] = 1;
    }
    for (int i = 2; i <= n; ++i) {
        if (f[i-1] == 0) {
            for (int j = 1; j <= m; ++j) {
                dp[i][j] = dp[i-1][j];
                if (j > 1) dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % MOD;
                if (j < m) dp[i][j] = (dp[i][j] + dp[i-1][j+1]) % MOD;
            }
        } else {
            int j = f[i-1];
            dp[i][j] = dp[i-1][j];
            if (j > 1) dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % MOD;
            if (j < m) dp[i][j] = (dp[i][j] + dp[i-1][j+1]) % MOD;
        }
    }
    int result = 0;
    for (int j = 1; j <= m; ++j) {
        result = (result + dp[n][j]) % MOD;
    }
    return result;
}

int main() {
    int n, m;
    cout << "Enter the number of elements (n) and the maximum value (m): ";
    cin >> n >> m;

    vector<int> f(n);
    cout << "Enter the series (0 for unknown, or an integer value for known positions): ";
    for (int i = 0; i < n; ++i) {
        cin >> f[i];
    }

    int result = countValidSeries(n, m, f);
    cout << "The number of valid series is: " << result << endl;

    return 0;
}

Flight series Counterโœ…
void fun(int i,int n,vector<int>&p,vector<int>&c,int x,int y,map<int,int>&m){
        if(i==n){
            m[x] = max(m[x],y);
            return ;
        }
        fun(i+1,n,p,c,x+p[i],y+c[i],m);
        fun(i+1,n,p,c,x,y,m);
        return ;
}

int solve(vector<int>&p,vector<int>&c,int w){

int n = p.size();

map<int,int>m1,m;
fun(0,n/2,p,c,0,0,m);
int x = 0;


for(auto &it:m){
      x=max(it.second,x);
      it.second = x;
}

fun(n/2,n,p,c,0,0,m1);

x=0;
for(auto &it:m1){
      x=max(it.second,x);
      it.second = x;
}

int ans = 0;

for(auto it:m){
     int r = w-it.first;
     auto itt = m1.upper_bound(r);
     if(itt != m1.begin()){
      itt--;
      ans = max(it.second+itt->second,ans);
     }
}

for(auto it:m1){
     int r = w-it.first;
     auto itt = m.upper_bound(r);
     if(itt != m.begin()){
      itt--;
      ans = max(it.second+itt->second,ans);
     }
}

return ans;

}

Getmaxquantityโœ…
BNY Mellon