๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.52K subscribers
5.56K photos
3 videos
95 files
9.7K 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<bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;int A[n];for(int i=0;i<n;i++)cin>>A[i];vector<vector<int>>minim(n,vector<int>(n,INT_MAX));
    for(int i=0;i<n;i++)minim[i][i]=i;
    for(int size=2;size<=n;size++)for(int st=0;st<=n-size;st++)
    {
        int en=st+size-1;
        if(A[minim[st+1][en]]>=A[st])minim[st][en]=st;else minim[st][en]=minim[st+1][en];
    }int dp[n+3][n+3];memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++)dp[i][i]=A[i];
    for(int size=2;size<=n;size++)for(int st=0;st<=n-size;st++)
    {
        int en=st+size-1;int x=minim[st][en];
        dp[st][en]=A[x];if(x-2>=0)dp[st][en]+=dp[st][x-2];if(x+2<=n)dp[st][en]+=dp[x+2][en];
    }cout<<dp[0][n-1];return 0;
}

Airtel โœ…
def shorten_string(s):
    stack = []
    for char in s:
        if stack and stack[-1] == char:
            stack.pop()
        else:
            stack.append(char)
    return ''.join(stack) if stack else "Empty String"

s = input().strip()
print(shorten_string(s))
class Solution {
public:
    long long maxValue(int n, int arr[]) {
        long long max_geek_value = 0;
       
        int max_right[n];
        max_right[n - 1] = arr[n - 1];
       
        for (int i = n - 2; i >= 0; --i) {
            max_right[i] = max(max_right[i + 1], arr[i]);
        }
       
        int max_left = arr[0];
       
        for (int i = 1; i < n - 1; ++i) {
            long long geek_value = static_cast<long long>(max_left - arr[i]) * max_right[i + 1];
            max_geek_value = max(max_geek_value, geek_value);
            max_left = max(max_left, arr[i]);
        }
       
        return max(max_geek_value, 0LL);
    }
};  GFG |JOB-THON 1
class Solution {
    Map<Integer, Boolean> mp = new TreeMap<>();

    public long MaxScore(int N, int arr[]) {
        int n = arr.length - 1;
        long dp[][] = new long[n + 1][n + 1];
        for (long[] a : dp)
            Arrays.fill(a, -1);
        return solve(0, n, arr, dp);
    }

    public long solve(int f, int b, int[] arr, long[][] dp) {
        if (b < f)
            return 0;
        if (dp[f][b] != -1)
            return dp[f][b];
        long min = mi(f, b, arr);
        long p1 = (long) arr[f] * (long) (b - f + 1) + min + solve(f + 1, b, arr, dp);
        long p2 = (long) arr[b] * (long) (b - f + 1) + min + solve(f, b - 1, arr, dp);
        return dp[f][b] = Math.max(p1, p2);
    }

    public long mi(int f, int b, int[] arr) {
        long min = Long.MAX_VALUE;
        for (int i = f; i <= b; i++) {
            min = Math.min(min, (long) arr[i]);
        }
        return min;
    }
} Job-thon 2
class Solution
{
    public:
    vector<int> geeksJourney(vector<int>& geeksTown, int n, vector<int>& journey, int m, vector<vector<int>>& queries, int q)
    {
        // code here
        vector<int> result;
        vector<pair<int, int>> subarrayIndices;

        for (int i = 0; i <= m - n; ++i) {
            bool match = true;
            for (int j = 0; j < n; ++j) {
                if (geeksTown[j] != journey[i + j]) {
                    match = false;
                    break;
                }
            }
            if (match) {
                subarrayIndices.push_back(make_pair(i, i + n - 1));
            }
        }

        for (int i = 0; i < q; ++i) {
            int left = queries[i][0];
            int right = queries[i][1];
            int count = 0;

            for (const auto& indices : subarrayIndices) {
                if (indices.first >= left && indices.second <= right) {
                    ++count;
                }
            }

            result.push_back(count);
        }

        return result;
    }
}; jon - thon 3
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <bits/stdc++.h>
using namespace std;

int solution(vector<string>&v, int n){
   int ans=0,count;
   for(int i=0; i<v.size(); i++){
       count=1;
       int idx=-1;
       int strln = v[i].length();
       for(int j=1; j<strln; j++){
           if(v[i][j]==v[i][j-1]) count++;
           else{
               if(count==n) ans++;
               count=1;
               idx=j;
           }
       }
       if(idx!=strln-1)
       if(count==n) ans++;
   }
   return ans;
}

int main() {
   int n,m; cin>>n>>m;
   vector<string>v(m);
   for(int i=0; i<m; i++) cin>>v[i];
   cout<<solution(v,n)<<endl;
    return 0;
}
#include<bits/stdc++.h>
using namespace std;

int solve(vector<vector<int>>&v, vector<vector<int>>&vis, int x, int y, int sum,int dx, int dy){
   if(vis[x][y]) return sum;
   if((x==0 and y==0) (x==0 and y==v[0].size()-1) (x==v.size()-1 and y==0) (x==v.size()-1 and y==v[0].size()-1)){
      sum+=v[x][y];
       return sum;
   }
   sum+=v[x][y];
   vis[x][y]=1;
   if(x+dx==v.size()
x+dx<0){
       if(dx==1) dx=-1;
       else dx=1;
   }
   if(y+1==v[0].size() || y+dy<0){
       if(dy==1) dy=-1;
       else dy=1;
   }
   return solve(v,vis,x+dx,y+dy,sum,dx,dy);
}

int solution(vector<vector<int>>&v, int x, int y){
    int n=v.size();
    int m=v[0].size();
    vector<vector<int>>vis(n,vector<int>(m,0));
    return solve(v,vis,x,y,0,1,1);
}
signed main(){
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    vector<vector<int>>v(n,vector<int>(m,0));
    for(int i=0; i<n; i++)
    for(int j=0; j<m; j++) cin>>v[i][j];
    cout<<solution(v,x,y)<<endl;
    return 0;
}

Visa ROBOT Traversalโœ…
#include <iostream>
#include <vector>
using namespace std;

vector<int> Solve(int N, int K) {
    vector<int> slots(K, 0);

    int bagCount = 1;
    while (N > 0) {
        for (int i = 0; i < K && N > 0; ++i) {
            if (bagCount <= N) {
                slots[i] += bagCount;
                N -= bagCount;
                bagCount++;
            } else {
                slots[i] += N;
                N = 0;
            }
        }
    }

    return slots;
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> result = Solve(N, K);
    for (int bags : result) {
        cout << bags << " ";
    }
    cout << endl;
    return 0;
}

Bag Distribution Algorithm C++โœ…
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int f = 0;
    int s = 1;
    int ans = 0;
    if (n == 0)
    {
        cout << 0;
    }
    if (n == 1)
    {
        cout << 1;
    }
    for (int i = 2; i <= n; i++)
    {
        ans = f + s;
        f = s;
        s = ans;
    }
    cout << ans;
}
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n)
{
    for (int i = 2; i <= sqrt(n); i++)
        if (n % i == 0)
            return false;
    return true;
}
int main()
{
    int n, m;
    cin >> n >> m;
    int a = 0;
    int b = 0;
    while (n < m)
    {
        if (isPrime(n))
        {
            a = n;
            break;
        }
        n++;
    }
    while (n < m)
    {
        if (isPrime(m))
        {
            b = m;
            break;
        }
        m--;
    }
    cout << a + b;
    return 0;
}
public static void main(String[] args) {
        String[] arr =new String[]{"aa", "aab", "b", "bbd", "d"};
        String tar = "aabbd";
        int len = tar.length();
        int[] dp = new int[len+1];
        Arrays.fill(dp, 9999);
        dp[0] = 0;
        for(int i = 1; i <= len; i++) {
            int cal = 0;
            for(int j = 1; j <= i; j++) {
                String sub = tar.substring(j-1,i);
                boolean found = false;
                for(int k = 0; k < arr.length; k++) {
                    if(arr[k].startsWith(sub)){
                        found = true;break;
                    }
                }
                if(found)dp[i] = Math.min(dp[i], 1 + dp[j-1]);
                System.out.print(i + " " + dp[i] + "    ");
            }
            // dp[i] = cal;
        }
        System.out.println(dp[len]);
    }

equal string trilogy โœ