- 15
- 82 465
Abhishek Saini
Приєднався 7 сер 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.
Leetcode Contest 410 Solutions | Hindi (Use Subtitles)
Like the video and subscribe if you found this useful, it motivates me to make more educational videos. DP problem starts from 2:45.
Contest Link - leetcode.com/contest/weekly-contest-410/
0:00 Problem A
0:54 Problem B
2:45 Problem C and D
10:10 Clever Optimization for D
Mouse I use - shorturl.at/hloAX
Keyboard I use - shorturl.at/elFHX
Microphone I use - shorturl.at/hpT13
#codeforces #codeforcessolutions #codechef #leetcode #leetcodesolutions
Contest Link - leetcode.com/contest/weekly-contest-410/
0:00 Problem A
0:54 Problem B
2:45 Problem C and D
10:10 Clever Optimization for D
Mouse I use - shorturl.at/hloAX
Keyboard I use - shorturl.at/elFHX
Microphone I use - shorturl.at/hpT13
#codeforces #codeforcessolutions #codechef #leetcode #leetcodesolutions
Переглядів: 3 868
Відео
Codeforces Round 964 Solutions | Hindi (use accurate subtitles for English)
Переглядів 1,5 тис.2 місяці тому
Like the video and subscribe if you found this useful, it motivates me to make more educational videos. Contest Link - codeforces.com/contest/1999 My submission link - codeforces.com/submissions/abhishek_saini 0:00 Problem A 0:20 Problem B 1:32 Problem C 2:36 Problem D 5:08 Problem E 8:22 Problem F 11:00 Problem G1 and G2 Mouse I use - shorturl.at/hloAX Keyboard I use - shorturl.at/elFHX Microp...
Only 3% Leetcoders can solve this DP Problem | Dynamic Programming | Leetcode Biweekly Contest 132
Переглядів 5 тис.4 місяці тому
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...
Codeforces Contest 944 Solutions | Let's upsolve at least one | Competitive Programming
Переглядів 3,4 тис.5 місяців тому
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
Переглядів 2,7 тис.6 місяців тому
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
Переглядів 4,8 тис.7 місяців тому
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
Переглядів 14 тис.8 місяців тому
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
Переглядів 3,9 тис.8 місяців тому
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
Переглядів 4,1 тис.9 місяців тому
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
Переглядів 3,2 тис.9 місяців тому
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
Переглядів 5 тис.10 місяців тому
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
Переглядів 11 тис.10 місяців тому
More Powerful Stack, Queue and Deque | Watch at 1.5x | Competitive Programming
how to know which on of this to use to solve any problem
Really great explanation!
Extraordinary bro, continue the Playlist. It is very rare to see this type of high quality content.
Sir currently I am in my 3 sem and doing dsa but not able to solve questions on codeforces...any advice regarding dsa and cp
Bro, Bahut hi sahi explanation... Especially loved the part, Where you, showed the dp relationship, and how the map helps replace it.... (You not only explained the question, But the way you showed the trick, IT sinks down in the brain, to help me further solve other questions....) Straight to the point solution....
Bhaiya How to thik directly about tabulation? Means i first need to think about recursive then i need to convert it into tabulation
is atcoder dp educational and cses dp question sufficient to solve such dp problem?
Definitely yes. But actually understanding those, not just 'knowing' solutions to all of those.
@@abhishekcode42 ok sir, Thank you!
from where we can learn dp for CP?
Ist question ke lia map ka use tha bhi
Not needed, you can do the same using if conditions
Can you explain in English 😢
Please explain in english sir❤
Hello Karthick, can you try turning on subtitles, subtitles are mostly very accurate.(turn on auto-translation from hindi to English in UA-cam subtitles option). Lemme know if auto-subtitles are not good, I will consider hiring someone for putting accurate manual english subtitles whenever it's in Hindi.
Nicely Explained✌️
Bro provide code in java too
Hi Yash, not very C++ specific data structures or anywhere. Try writing this in Java by taking C++ reference.
well explained !!
❤️
I am here after seeing your LinkedIn post. Hope we get a new video on Div 2
Based on my experience and understanding, after a certain level people would rather read blogs than watch videos (including me), that fact doesn't give any motivation to make videos for harder topics or too hard problems.
@@abhishekcode42 ok bhaiya
Hindi me maja aya sir keep it up!
Keep them coming
Was giving first contest. 4 ke idea aaye. 3 mai hidden me gya😭
Happens in starting, with time it will improve, good luck!
Abhishek Bhai i have a query i know Bhai aapne m.tech ka exam nhi diya hai but Bhai I'm preparing for Gate cse exam brother suggest me best Book of c programming and algorithm in depth
Hey, "Let us C" is a popular one for C. To be honest though, I have never read myself but have heard good reviews from a lot of people. For algorithms, if you want a proper indepth good book, cormen I have personally read and liked.
is it possible to do the same for Max deque ?
Yes absolutely
Hi bhaiya, For the past 2 months, I have been trying Competitive Programming , but most of the time I am unable to handle math-related problems. Since the majority of CP problems are math-related, please suggest how I can improve my math skills to better handle CP problems. Also, please suggest some sources.
class Solution { public int maximumLength(int[] nums, int k) { int n = nums.length; int[][][] dp = new int[n][k + 1][n + 1]; for (int[][] d : dp) { for (int[] row : d) { Arrays.fill(row, -1); } } return fxn(n - 1, nums, k, n, dp); } int fxn(int idx, int[] arr, int k, int prevIdx, int[][][] dp) { if (idx < 0) { return 0; } if (dp[idx][k][prevIdx] != -1) { return dp[idx][k][prevIdx]; } int notTake = fxn(idx - 1, arr, k, prevIdx, dp); int take = 0; if (prevIdx == arr.length || arr[idx] == arr[prevIdx]) { take = 1 + fxn(idx - 1, arr, k, idx, dp); } else if (arr[idx] != arr[prevIdx] && k > 0) { take = 1 + fxn(idx - 1, arr, k - 1, idx, dp); } dp[idx][k][prevIdx] = Math.max(notTake, take); return dp[idx][k][prevIdx]; } }what optimization can be done here like it passed 3rd one but not 4th one ??!
Bhai shorts ki DSA series upload Karo then tier 2-3 wale relate kar payenge .. shorts video bnao nhi toh time waste hai on UA-cam 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 UA-cam 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