๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
#include <bits/stdc++.h>
using namespace std;
 
  bool check(int a,int b,map<int,vector<int>> m){
     
      if(a==b) return 1;
     
      for(auto &x : m[a]){
          if(check(x,b,m)) return 1;
      }
     
      return 0;
  }
  
  int main() {
   
   
    int n,l;
    cin>>n>>l;
   
    vector<int> v1(n) , v2(l);
    map<int,vector<int>> m;
    for(int i=0;i<n;i++){
         cin>>v1[i];
    }
    for(int i=0;i<l;i++){
        cin>>v2[i];
    }
   
    for(int i=0;i<n-1;i++){
        m[v1[i]].push_back(v1[i+1]);
    }
     for(int i=0;i<l-1;i++){
        m[v2[i]].push_back(v2[i+1]);
    }
  
   int a,b;
   cin>>a>>b;
  
   bool ok=check(a,b,m);
   if(ok){
       cout<<"YES";
   }else{
       cout<<"NO";
   }
  
  
  }

Shopping Spree โœ…
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

int memo(int n,vector<int> &dp){
        if(n <= 1) return 1;
        else if(n==2) return 2;
        else if(n==3) return 4;
       
        if(dp[n] != -1) return dp[n];
       
        return dp[n] = (memo(n-1,dp) + memo(n-2,dp) + memo(n-3,dp))%MOD;
}

int climbStairs(int n) {
    vector<int> dp(n+1,-1);
    return memo(n,dp);
}

int main()
{
    cout<<climbStairs(4);

    return 0;
}

Stair
C++
class SuperMarket {
    private Map<Integer, Customer> customers = new HashMap<>();
    private Map<Integer, Queue<Customer>> lines = new HashMap<>();

    public void OnCustomerEnter(int customerId, int lineNumber, int numItems) {
        Customer customer = new Customer(customerId, lineNumber, numItems);
        customers.put(customerId, customer);
        if (!lines.containsKey(lineNumber)) {
            lines.put(lineNumber, new LinkedList<>());
        }
        lines.get(lineNumber).add(customer);
    }

    public void OnBasketChange(int customerId, int newNumItems) {
        Customer customer = customers.get(customerId);
        int oldNumItems = customer.getNumItems();
        customer.setNumItems(newNumItems);
        if (oldNumItems > newNumItems) {
            return;
        }
        Queue<Customer> line = lines.get(customer.getLineNumber());
        line.remove(customer);
        line.add(customer);
    }

    public void OnLineService(int lineNumber, int numProcessedItems) {
        Queue<Customer> line = lines.get(lineNumber);
        if (line.isEmpty()) {
            return;
        }
        Customer customer = line.peek();
        int numItems = customer.getNumItems();
        if (numItems <= numProcessedItems) {
            line.remove();
            customers.remove(customer.getCustomerId());
            System.out.println(customer.getCustomerId());
        } else {
            customer.setNumItems(numItems - numProcessedItems);
        }
    }

    public void OnLinesService() {
        for (int lineNumber : lines.keySet()) {
            OnLineService(lineNumber, Integer.MAX_VALUE);
        }
    }
}

class Customer {
    private int customerId;
    private int lineNumber;
    private int numItems;

    public Customer(int customerId, int lineNumber, int numItems) {
        this.customerId = customerId;
        this.lineNumber = lineNumber;
        this.numItems = numItems;
    }

    public int getCustomerId() {
        return customerId;
    }

    public int getLineNumber() {
        return lineNumber;
    }

    public int getNumItems() {
        return numItems;
    }

    public void setNumItems(int numItems) {
        this.numItems = numItems;
    }
}

Supermarket Checkout โœ