![Abhishek Saini](/img/default-banner.jpg)
- 13
- 65 937
Abhishek Saini
Registrace 7. 08. 2023
Check out playlists and live tab for exploring already uploaded educational videos.
This channel is for educational videos about Algorithms and Competitive Programming.
A few things about me -
- I have the master title with 2200 rating on Codeforces.
- I'm currently working for Google as a Senior Software Engineer.
- Before Google, I worked for the HFT firm Tower Research Capital.
- I did my graduation from IIT Kharagpur.
- I like reading books about physics, finance, philosophy, psychology, etc.
- I play games like table tennis, badminton, chess, etc.
This channel is for educational videos about Algorithms and Competitive Programming.
A few things about me -
- I have the master title with 2200 rating on Codeforces.
- I'm currently working for Google as a Senior Software Engineer.
- Before Google, I worked for the HFT firm Tower Research Capital.
- I did my graduation from IIT Kharagpur.
- I like reading books about physics, finance, philosophy, psychology, etc.
- I play games like table tennis, badminton, chess, etc.
Only 3% Leetcoders can solve this DP Problem | Dynamic Programming | Leetcode Biweekly Contest 132
If you found this helpful, like and comment to encourage me to make more such videos.
Problem Link - leetcode.com/contest/biweekly-contest-132/problems/find-the-maximum-length-of-a-good-subsequence-ii/
0:00 Introduction
0:21 Problem Statement
1:20 Explanation Start
11:47 Clever Optimization
14:22 Code
Mouse I use - shorturl.at/hloAX
Keyboard I use - shorturl.at/elFHX
Microphone I use - shorturl.at/hpT13
Only 3% Leetcoders can solve this DP Problem | Dynamic Programming | Leetcode Biweekly Contest 132
#leetcode #dynamicprogramming #codeforces #codeforcessolutions #codechef
Problem Link - leetcode.com/contest/biweekly-contest-132/problems/find-the-maximum-length-of-a-good-subsequence-ii/
0:00 Introduction
0:21 Problem Statement
1:20 Explanation Start
11:47 Clever Optimization
14:22 Code
Mouse I use - shorturl.at/hloAX
Keyboard I use - shorturl.at/elFHX
Microphone I use - shorturl.at/hpT13
Only 3% Leetcoders can solve this DP Problem | Dynamic Programming | Leetcode Biweekly Contest 132
#leetcode #dynamicprogramming #codeforces #codeforcessolutions #codechef
zhlédnutí: 4 440
Video
Codeforces Contest 944 Solutions | Let's upsolve at least one | Competitive Programming
zhlédnutí 3,3KPřed měsícem
Like, Comment and Subscribe to encourage me to make more educational content. 0:00 Introduction 0:17 Problem A 0:45 Problem B 2:25 Problem C 5:00 Problem D 8:12 Problem E 13:50 Problem F 20:07 Problem G 25:40 Problem H Mouse I use - shorturl.at/hloAX Keyboard I use - shorturl.at/elFHX Microphone I use - shorturl.at/hpT13
Simplest Advanced Technique | Small to Large Merging | Time Complexity Analysis | DSA | CP
zhlédnutí 2,3KPřed měsícem
Like and comment on the video to encourage me to make more such educational videos. For interested folks, here is the editorial written by me which I showed in the video - atcoder.jp/contests/abc350/editorial/9842 0:00 Why Simplest Advanced Technique 0:29 Starting of Tutorial 4:38 How to Improve 6:50 Proof and Complexity Analysis (Most Important)
Guaranteed way to improve ratings in Codeforces and DSA skills
zhlédnutí 4KPřed 2 měsíci
You can also use my complete solutions for this problem set for help if you get really stuck [Please first try your best to solve on your own for best learning] - github.com/Abhishek-Saini/educational/tree/main/cses I highly recommend solving this problem set. This teaches super useful ideas starting from beginner to the most advanced ones. Subscribe to encourage me to make more and more educat...
Explaining My Competitive Programming Setup and Template | DSA Setup for Online Coding Contests
zhlédnutí 12KPřed 4 měsíci
If you found this useful, like and comment on the video, that is very encouraging for me to make more such educational videos. Check out the playlist "Powerful Data Structures" for learning powerful data structures in a simple way. 0:00 Introduction 1:00 CP Setup 8:27 Template for Cpp Mouse I use - shorturl.at/hloAX Keyboard I use - shorturl.at/elFHX Microphone I use - shorturl.at/hpT13
Codeforces Round 925 Intuitions | Problem G Recommended For Learning
zhlédnutí 3,8KPřed 4 měsíci
If you found this useful, like and comment on the video, that is very encouraging for me to make more such educational videos. Contest Link - codeforces.com/contest/1931 My Implementation can be seen here - codeforces.com/submissions/abhishek_saini 0:00 Introduction 0:50 Problem A 1:47 Problem B 4:30 Problem C 6:30 Problem D 10:16 Problem E 17:07 Problem F 24:47 Problem G Mouse I use - shorturl...
Rolling Median | Median of all subarrays of fixed size | Leetcode Contest 122
zhlédnutí 3,1KPřed 5 měsíci
If you found this useful, like and comment on the video, that is very encouraging for me to make more such educational videos. Last Problem from Leetcode biweekly contest 122 which uses the combination of both variations we discussed. My implementation can be found here - leetcode.com/submissions/detail/1151770802/ Mouse I use - shorturl.at/hloAX Keyboard I use - shorturl.at/elFHX Microphone I ...
Simplest Explanation of Square Root Decomposition | Developing Intuition
zhlédnutí 2,7KPřed 5 měsíci
If this video gets 500 likes or 100 comments, I will record a video talking about different variations and example problems of the technique explained in the video. If you found this useful, like and comment on the video, that is very encouraging for me to make more such educational videos. Subscribe for more such content. Problem to try to test your implementation - cses.fi/problemset/task/164...
Codeforces Round 918 | Understanding Dijkstra Algorithm Better | Sub Array Technique
zhlédnutí 5KPřed 5 měsíci
Feel free to watch in 1.25x if you feel the need. Problems E, F, and G are must-try for beginners. Each problem teaches a commonly used concept. Especially problem G tests your fundamental understanding of the Dijkstra algorithm. This is an experimental video editorial. I would look for feedback on whether video editorial is useful or not. This video explains the problems E, F, and G of Codefor...
More Powerful Stack, Queue and Deque | Watch at 1.5x | Competitive Programming
zhlédnutí 9KPřed 5 měsíci
This is my first video on CZcams. Like and comment, so that it reaches more folks, that would motivate me to make more such videos. Please suggest topics you want to learn next. Subscribe for more such educational videos. Please give me feedback about the video quality but please be a little kind. Will decide on the topics of the next videos and also things like If I should go for easier or har...
Bhai shorts ki DSA series upload Karo then tier 2-3 wale relate kar payenge .. shorts video bnao nhi toh time waste hai on CZcams this is my opinion 😊.. best of luck Bhai
Yaar you're right but 1 minute m kaise seekhenge log. Views to aa jayenge usse but noone will learn anything useful :(
@@abhishekcode42 Bhai.. Fireship CZcams channel ki tarah video banao
Bahiya ive written its rec code its showing tle 3d dp
class Solution { public: int dp[5010][55][5010]; int f(int i,vector<int>&a,int k,int lst){ if(i==a.size())return 0; if(dp[i][k][lst+5]!=-1) return dp[i][k][lst+5]; int ans=-1e5; if(lst == -1 || a[lst]== a[i]){ ans =max(ans, 1 + f(i+1,a,k,i)); } else{ if(k){ ans =max(ans, 1+f(i+1,a,k-1,i)); } } ans =max(ans,f(i+1,a,k,lst)); return dp[i][k][lst+5]=ans; } int maximumLength(vector<int>& a, int k) { memset(dp,-1,sizeof dp); return f(0,a,k,-1); } };
Great explanation my man 🤗
Thanks a ton bhaiya for the help.....🙏🏻🙏🏻🙏🏻
class Solution: def maximumLength(self, nums: List[int], k: int) -> int: n = len(nums) c = Counter(nums) if k == 0: return max(c.values()) if max(c.values()) == 1: return min(k + 1, n) runs = {} best = [0] * (k + 1) for x in nums: if x not in runs: runs[x] = [1] * (k + 1) else: runs[x] = [z + 1 for z in runs[x]] runs[x][1:] = [max(lo + 1, xrun) for lo, xrun in zip(best, runs[x][1:])] best[1:] = [max(lo + 1, b) for lo, b in pairwise(best)] best = [max(b, xrun) for b, xrun in zip(best, runs[x])] return max(best) that's Python easy solution
i have a doubt in second optimization (was able to think of first one on own). The doubt is why prev index doesn't matter. condition says nums[i] != nums[prev] . Like assume nums[i] =1 say at some i we and trying to calculate for j=3 and there was a sequence let say 1 2 2 1 so obv a length of 4 is already precalculated for some prev index also ending at 1 and j=2 as u can see . Now if you will calculate ans for current i you will say 1 + dp[p][2] as you ans => 1 + 4 but actually this is wrong na coz you made a sequence of length 5 saying there are 3 indices in 1 2 2 2 1 1
I didn't completely understand what you meant? Are you saying that we would be counting different pairs as 3 for that subsequence, but different pairs for that is 2 only?
@@abhishekcode42 yes dp state is ending at i with let say 3 different indices but if u are saying it doesn’t matter prev index then don’t u think you will be calculating ans for dp[i][2] and taking maximum with dp[i][3]
where to study dp from, I always write the recursive solutions but can't write the iterative ones, even here my solution to the problem with smaller constraints got accepted but couldn't solve the 4th one, something similar happened in one of the problems of recent Amazon hack-on OA. Please suggest some resource
If someone solves this using DP with O(n*n*k) TC and SC, is it good enough to get Strong Hire or Hire verdict at Google for L4 and above?
ya i understood this quiz but we could have done one more thing....iterate from (0--->k) and use a temp array to store the updated values for overallMaxForK array throughout the j loop and then do overallMaxForK = temp bcoz we require values of overallMaxForK array only for p = (0--->i-1) so we can update the array once the j loop is over Am I right ??
yes, that works
I was using only a map to store the length of the max sequence ending at that particular value...so had problem while updating the map, and the second array which represent the length of the longest subseq with atmost k different pairs simultaneously....implementation issues...but glad i could think in somewhat the same direction as yours !!
can anyone explain why it is giving MLE bool check(vector<int>&ele,int k){ int n=ele.size(); int count=0; for(int i=0;i<=n-2;i++){ if(ele[i]!=ele[i+1]){ count++; } } return count<=k; } vector<vector<int>>ans; void getsub(vector<int>&nums,int i,int n,vector<int>&ele){ if(i>=n){ ans.push_back(ele); return; } ele.push_back(nums[i]); getsub(nums,i+1,n,ele); ele.pop_back(); getsub(nums,i+1,n,ele); } int maximumLength(vector<int>& nums, int k) { int n=nums.size(); vector<int>ele; getsub(nums,0,n,ele); int MAX=0; for(int i=0;i<ans.size();i++){ if(check(ans[i],k)){ int m=ans[i].size(); MAX=max(MAX,m); } } return MAX; }
Still not understood
Did you understand the part before doing the optimization?
@@abhishekcode42 i have a doubt in second optimization (was able to think of first one on own). The doubt is why prev index doesn't matter. condition says nums[i] != nums[prev] . Like assume nums[i] =1 say at some i we and trying to calculate for j=3 and there was a sequence let say 1 2 2 1 so obv a length of 4 is already precalculated for some prev index also ending at 1 and j=2 as u can see . Now if you will calculate ans for current i you will say 1 + dp[p][2] as you ans => 1 + 4 but actually this is wrong na coz you made a sequence of length 5 saying there are 3 indices in 1 2 2 2 1 1
@@abhishekcode42 yes after watching again I understood . thank you .Can you Upload Leetcode weekly contest 401 3,4 which has dp with optimisation
thanks bhaiya 🙏🙏 quite helpful video .... best thing for me is I was trying this from last 1hr but was unable to come up with a soln and i found this video.
Most welcome 😊
Answer to quiz: The reverse might result in wrong answer because we don't wanna use the result of something[j - 1] or something[j] computed at index i to be used for something[j] at the same index.
Perfect!
@@abhishekcode42 thanks bhaiya. Server issues k lia concentration hat gaya tha islia ulta kar dia rha phir debug kia 😂
Lol :D, dukh jhel chuke ho quiz question ka already
@@abhishekcode42 haa 😂
@@abhishekcode42 ya i understood this but we could have done one more thing....iterate from (0--->k) and use a temp array to store the updated values for overallMaxForK array throughout the j loop and then do overallMaxForK = temp bcoz we require values of overallMaxForK array only for p = (0--->i-1) so we can update the array once the j loop is over Am I right ??
Nice Thank you... C felt kind of standard but for D i thought similar approach but end up storing for each K using vector<map> and then finding maxx for each k for every iteration.. Took O(n*k*k) . It got accepted 😅 tho I was expecting it to be MLE.
Nice haha :D I agree, feels on the boundary time complexity wise as well, perhaps little weak test cases.
@@abhishekcode42 Ya very true ...
bro can you please share your code
sir the lecture was godly.
Thank you 😊
Sorry brother, you lost me at white theme. BTW, keep up the good work.
In the problem E suppose i declare both the array inside Int main then i get some random output why ?? rest mine logic was same , also i have matched from your submission
random output on cf only in my code editor it gives ouput according to the test case only
#include <bits/stdc++.h> using namespace std; // vector<long long> A; // vector<long long> B; long long A[300010]; long long B[300010]; int main() { long long tt; cin >> tt; while (tt--) { long long n, k, q; cin >> n >> k >> q; for (long long i = 0; i < k; i++) { cin >> A[i]; } for (long long i = 0; i < k; i++) { cin >> B[i]; } while (q--) { long long d; cin >> d; int idx = lower_bound(A, A+k, d) - A; long long time =0; if (A[idx] == d) { cout << B[idx] << " "; } else { idx--; assert(idx < n - 1); time = B[idx] + (B[idx + 1] - B[idx]) * (d - A[idx]) / (A[idx + 1] - A[idx]); cout << time << " "; } } cout<<endl; } return 0; }
this was my code suppose i declare int main the it give me wrong output on cf
also i have tried it using vector i have not gone the correct output on cf then how can i replace array with vector
ThankYou
Today in Codechef 134 B i solved 3rd problem using it. It was amazing as you Sir.
Awesome!
Time complexity(fun part was truly fun) until i saw the last ques, that one's a menace. Need to grow a lot. Thanks for the video!
For problem 'F' Let's say we are calculating for x = 6 and i = 6 in that case cnt = 0 here we didn't count any extra points, then why would we subtract - 1 from the count
You're right but because of what this problem is specifically asking we don't have to worry about these edge cases. They get offsetted by itself. But you can look at this new submission I made - Here I updated it to do make sense according to how you're thinking. codeforces.com/contest/1971/submission/260660321
int lastElementLessThanD(vector<int> arr, int d) { auto it = std::lower_bound(arr.begin(), arr.end(), d); if (it == arr.begin()) { // If lower_bound returns the beginning of the array, // it means all elements are greater than or equal to d. return -1; // Indicating no such index found } else { // Return the index of the last element less than d return std::distance(arr.begin(), --it); } } int32_t main() { // your code goes here jaldi_kar_kal_panvel_nikalna_hein int t = 1; cin >> t; while(t--){ int n, k, q; cin >> n >> k >> q; vi a(k); scan(a,k); vi b(k); scan(b,k); while(q--){ int d; cin >> d; if(d <= a[0]){ cout << (d*b[0])/a[0] << " "; continue; } if((k-2) >= 0 && d >= a[k-2]){ int x = d - a[k-2]; int tot_d = n - a[k-2]; int tot_t = b[k-1] - b[k-2]; int prin = b[k-2] + (x * tot_t) / tot_d; cout << prin << " "; continue; } int idx = lastElementLessThanD(a,d); // cout << endl << d << " : " << idx << endl; int x = d - a[idx]; int tot_d = a[idx+1] - a[idx]; int tot_t = b[idx+1] - b[idx]; int ans = b[idx] + (x * tot_t) / tot_d; cout << ans << " "; } cout << endl; } return 0; } Sir, can you plz tell me where is the problem in this solution for Problem E?? I have used BS on array "a" only ..but it have me TLE on 7th case.
Paste copy to pastebin or ideone and share link
Time complexity +1
Amazing as always! Can you suggest some resources for bit manipulation. I always feel very underconfident while solving them.
This should be useful cp-algorithms.com/algebra/bit-manipulation.html
Bhaiya I am not getting this in Problem F lets say x is 0. then for that x we calculated the max y possible. But this specific x and y combination will contribute in both quadrants. Then how come multiplying it by 4 gives the correct answer
You're right but because of what this problem is specifically asking we don't have to worry about these edge cases. They get offsetted by itself. But you can look at this new submission I made - Here I updated it to do make sense according to how you're thinking. codeforces.com/contest/1971/submission/260660321
@@abhishekcode42 Got it thnxx bhaiya. Thankyou for taking out time from your busy schedule and clearing my doubt
I think there is a small correction in explanation of problem E. In the example that you took you multiplied distance with distance instead of time: explained equation: d * (a[i] - a[i-1) / (b[i] - b[i - 1]) correct equation: d * (b[i] - b[i - 1])/(a[i] - a[i - 1])
Oh Yes, you're right. That's a legit typo.
in problem F we are multiplying by 4 for all the points but why are we not checking if any of our points lie on x or y axis bcz then we should multiply by 2 only
You're right but because of what this problem is specifically asking we don't have to worry about these edge cases. They get offsetted by itself. But you can look at this new submission I made - Here I updated it to do make sense according to how you're thinking. codeforces.com/contest/1971/submission/260660321
i do not get it why cnt(10)+cnt(01)-1 in problem d
Let's go step by step. Do you get why cnt(10) is added?
Problem E for way more easier than D ,I wasted a lot of time in problem D finding the edges cases
I did binary search,,,,but ended in tle on 7th case ..... don't know why..... because at best, you have to use BS.....
It took me more time to solve E though. I feel problem G was easy...I wasted my time understanding F
@@ce063_gautamlathiya5 I also used binary also on array a , got my solution accepted, but after the contest my solution was hacked 😢😢
in problem what was the apprroach for optimal solution, it was not clearly understood
Which problem
Thank you vaia💜
For Problem C : Both points of the second arc has to be on the same side of the first arc
If on the same side, then no intersection. One on one side and other on the other side needed for intersection.
In problem 2, I tried to store all the chars in map and if map.size was 1 it was impossible or else it would be possible so I did print the last half and then first half of string which was giving me wrong ...I didn't get why ?
I guess if the string can be converted into some kind of palindrome
If the string had same halves, it would fail like "abcabc", you could simply swap any two distinct characters and it would work.
Yes, simplest example you will issue with is "abab"
I tried to reverse the string if all characters are not same then I got wrong answer but it’s also not possible when string is palindrome. But you explain it very easy way thank you
If string length is one print no Else //I shifted every chars by one index abc --> bca If they are equal print no else print yes and the new string
Thank you for sharing these so quickly Abhishek, I really like the way you deconstruct problems into simple explanations.
Thanks sir! Will watch tomorrow in local while traveling to college...
Sir what if , for(int i=1;i<=m;i++) { for(int j=1;j<=n;j++) { // code in o(1) } } TC - O(m * n) but what if for(int j=1;j<=n*m;j++) { // code in o(1) } TC - O(n*m) both time complexities are same or differnt
Correct, they are same.
Thank you sir
1:29:50 SELF REFERENCE
1:32:23 I didn't get how i-4 , k=4 has 0 operations and how i=3 , k=2 has 2 operations? like all we are doing is multiple k by i so how is it taking more than 1 operations ? and in case if i=4, k=4 what is happening ? i ididn't get it at all
Take a pen paper and track value of i and k at each point, try that with focus. If you still don't get it after that, then comment back.
Awesome time complexity lecture!!!
Striver nhi pta kya tumko
Awesome
sir please change the mic, your voice is not clear
Try with a different earphone once, overall voice quality feedback has been good.
To be very honest, after your first class on cf contest discussion, I thought I have wasted my 1k rs at wrong place but from todays session I proved wrong. Thanks for this amazing session , Now I can say I have learned something new today
Good to know, warm feels in reading this. It's practically super-hard to make editorials useful for each and every person because by definition contest problem can have any topic at all and in limited time you can only go in depth of selected topics and not everything.
after all these years, i am able to understand the time complexity. Thanks Sir!
what a good exapmles thanks sir
Nice sir, fully Understand
Sir Are you Teach "cp" ? in Upcoming video,
That's what we want , now sir take it from basic to advanced I know you will can.
sir mt bol bhaiya bol!
Yes pls bring stl and arrays