๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.52K subscribers
5.56K photos
3 videos
95 files
9.68K 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
int lengthOfLIS(vector<int>& nums) {
        vector<int>dp(nums.size(),1);
        for(int i = 0; i < nums.size(); i++)
            for(int j = i -1 ; j >= 0; j--)
               if(nums[i] > nums[j]) dp[i] = max(dp[i], 1 + dp[j]);
        return *max_element(dp.begin(),dp.end());
    }
};

Good subsequenceโœ…
(Oracle)
string getLongestRegex(string a, string b, string c)
{
  const size_t n = a.size();
  int idx = -1;
  for (int i = 0; i < n; i++) {
    if (c[i] != a[i] && c[i] != b[i]) { idx = i; }
  }
  if (idx == -1) return "-1";
  string res;
  for (int i = 0; i < n; i++) {
   
    if (i == idx) {
      string cur = "[";
      for (int j = 'A'; j <= 'Z'; j++)  if (j != c[i]) cur += j;
      cur += "]";
      res += cur;
    } else {
      res += "[ABCDEFGHIJKLMNOPQRSTUVWXYZ]";
    }
  }
  return res;
}

Amazon โœ…
#include<bits/stdc++.h>
using namespace std;
    vector<int> smallestRange(vector<vector<int>>& nums) {
        vector<int>res={-100000,100000};
        int k=nums.size();
        int maxi=INT_MIN;
        priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>>pq;
        for(int i=0;i<k;i++){
            int num=nums[i][0];
            vector<int>vec{num,0,i};
            //0th minimum element of list
            //1st index of element from the vector
            //2nd index of the vector
            //1st <4,0,0> 2nd <0,0,1> 3rd <5,0,2>
            maxi=max(maxi,num);//took the max of members //5
            pq.push(vec);
            //<0,0,1><4,0,0><5,0,2>
        }
        while(true){//until condition breaks
            vector<int>minval=pq.top();//<0,0,1>
            pq.pop();//<4,0,0><5,0,2>
            if(res[1]-res[0]>maxi-minval[0]){//5-0=5
                res[0]=minval[0];//res[0]=0
                res[1]=maxi;//res[1]=5
            }
            minval[1]++;//<0,1,1>,now from which we poped element in queue that min element containing vector , we should choose another element
            vector<int>vec2=nums[minval[2]];//minval[2]=1,so <0,9,12,20>
            if(minval[1]==vec2.size()){//1!=4
                break;
            }
            else{
                minval[0]=vec2[minval[1]];//minival[0]=vec2[1]=9
                maxi=max(maxi,vec2[minval[1]]);//maxi=max(5,9)=9
                pq.push(minval);//push <9,1,1>
            }
        }
return res;
    }
    int main(){
        int m,n;
        cin>>m>>n;
        vector<vector<int>>v(m,vector<int>(n));
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                cin>>v[i][j];
            }
            sort(v[i].begin(),v[i].end());
        }
        vector<int> ans = smallestRange(v);
        cout<<ans[0]<<" "<<ans[1];
    }

E comm
Amazon โœ…
#include <bits/stdc++.h>
  using namespace std;
 
const int N = 1e5+1;
queue<int>q[N];

void solve(){
 
  int n,k;
  cin>>n;
 
  // 1 2 3
 
  vector<int>v(n);

 
  int ans = 1e9;
 
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
 
  cin>>k;
 
    for(int i=0;i<n;i++){
     
      if(q[v[i]].size()==k)q[v[i]].pop();
     
      if(q[v[i]].size()==k-1){
        ans = min(i-q[v[i]].front(),ans);
       
      }
      q[v[i]].push(i);
  }
 
 
  if(ans == 1e9){cout<<"-1"<<endl;return;}
  
 
  cout<<ans-k+1<<endl;
  return;
 
 

 
 
 
}

  signed main() {

    solve();

    return 0;

  }

this was video streaming โœ…
Amazon
int64_t getDiscountPairs(int x, vector<int> price)
{
  const size_t n = price.size();
  map<int, int64_t> cnt;
  int64_t res = 0;
  for (int i = 0; i < n; i++) {
    int uu = price[i];
    int v = uu % x;
    if (v == 0) res += cnt[0];
    else res += cnt[x - v]; 
    cnt[v]++;
  }
  return res;
}

use long instead of int_64

Amazon โœ…
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include <bits/stdc++.h>
using namespace std;

class SinglyLinkedListNode {
public:
    int data;
    SinglyLinkedListNode* next;

    SinglyLinkedListNode(int node_data) {
        this->data = node_data;
        this->next = nullptr;
    }
};

SinglyLinkedListNode* findLongestList(SinglyLinkedListNode* head) {
    if (!head) return nullptr;

    SinglyLinkedListNode* curr = head;
    SinglyLinkedListNode* start = head;
    SinglyLinkedListNode* bestStart = head;

    int length = 1;
    int bestLength = 1;

    while (curr->next) {
        if (curr->data >= curr->next->data) {
            length++;
        } else {
            if (length > bestLength) {
                bestLength = length;
                bestStart = start;
            }
            length = 1;
            start = curr->next;
        }
        curr = curr->next;
    }

    // Check at the end in case the best sub-list is at the very end.
    if (length > bestLength) {
        bestLength = length;
        bestStart = start;
    }

    // Truncate the list after the longest non-increasing sub-list
    SinglyLinkedListNode* temp = bestStart;
    for (int i = 1; i < bestLength && temp; i++) {
        temp = temp->next;
    }
    if (temp) {
        temp->next = nullptr;
    }

    return bestStart;
}

C++โœ