Sliding Window Technique + 4 Questions - Algorithms

  Рет қаралды 125,381

QuanticDev

QuanticDev

Күн бұрын

Пікірлер: 83
@QuanticDev
@QuanticDev 4 жыл бұрын
12:40 I had "exponential complexity" on screen which should actually read "quadratic (polynomial) complexity" instead. 26:09 The actual space complexity of last question is O(m), where "m" is the number of distinct chars in the "Desired Characters" list. I tweaked my algo a little but forgot to update the space complexity value for the video.
@velvetinskin6567
@velvetinskin6567 Жыл бұрын
Oh thank goodness… I was about to pull my hair trying to figure out how to solve it in O(1) space complexity!
@fionamatu4996
@fionamatu4996 4 жыл бұрын
I wish we could have more of these kinds of windows which cover techniques applicable for each class of problem. Very helpful for when you need to quickly pick out what method and data structure to use for a scenario. Thank you for this video!
@08JuHan
@08JuHan 2 жыл бұрын
Kudos on wrapping up both sliding window and interview tips in the same video. Thanks a lot for posting it!
@praveensidda9946
@praveensidda9946 2 жыл бұрын
I always had the confusion regarding the sliding window problems, but kudos to your video, it made the sliding concept very clear . the application part is really great
@user-ov5nd1fb7s
@user-ov5nd1fb7s 3 жыл бұрын
Here is a nice trick question. Given an array of positive integers, return the maximum subarray. It's a 1 liner function maxSubArray(arr []uint){return arr;}.
@QuanticDev
@QuanticDev 3 жыл бұрын
Haha. These things happen a lot in interviews. Then the interviewers try to modify the question with "oh my bad, let me add some more constraints".
@cesaredecal2230
@cesaredecal2230 4 жыл бұрын
Some really really high quality content here. Thank you! I hope you will continue to upload more algorithm videos.
@QuanticDev
@QuanticDev 4 жыл бұрын
I will. Thanks!
@AnandKumar-kz3ls
@AnandKumar-kz3ls Жыл бұрын
this is top tier explanation i used to apply sliding window blindly never know the rules thanks bro
@benz6234
@benz6234 4 жыл бұрын
Thanks for this. I really enjoyed the format of this video. That is, explanation of a commonly used algorithm, and how it can be utilized in various levels of difficulties. It helped me understand the use case in each, which helped me recognize patterns of when to use the algorithm. I hope to see more videos in this kind of format.
@QuanticDev
@QuanticDev 4 жыл бұрын
I'm now producing one for Fibonacci puzzles with many questions in it. Enjoy!
@simonruber5419
@simonruber5419 2 жыл бұрын
Thanks so much for sharing :-)! I think the trick you apply to solve Question 2, (even though you mention that it's not recommended) does not work at all. When adding a constant to all elements, then subarrays of different lengths are affected differently, therefore the structure of the solution changes. E.g. when adding 5 to all elements, (one would search for a subarray with value 10 then I assume). The in the original array valid answer of [0,5] = 5 would be transformed to [5,10] = 15 which would not be a valid subarray in the transformed problem.
@keerthivasan764
@keerthivasan764 2 жыл бұрын
Bro do you find solution for second one?
@soufianeaouri6205
@soufianeaouri6205 2 жыл бұрын
@@keerthivasan764 here is a solution
@TeomanSoygul
@TeomanSoygul Жыл бұрын
Ah, I should have mentioned it. You don't look for 10, instead you look for 5 + 5 * k, where k is the no of elements in the current window. That would make [0,5] = 15 = 5 + 5 * 2, and it would be valid. As you observed, each time we expand the window, we are adding +5 to the final sum that we are looking for, and -5 each time we shrink the window. Pre-processing arrays like this is sometimes very useful, but obviously a pretty bad solution here.
@TeomanSoygul
@TeomanSoygul Жыл бұрын
@@keerthivasan764 You can easily apply Kadane's Algorithm to solve the second question variant that has negatives in it: kzbin.info/www/bejne/apTWcqateNCLkK8
@RiteshKudalkar
@RiteshKudalkar 6 ай бұрын
It still doesn't work. It fails to capture the window [5].
@AlexA-vo8bk
@AlexA-vo8bk 2 жыл бұрын
You deserve million subscribers, your content is gold, with detailed explanation. Thank you
@shantanugaware8780
@shantanugaware8780 Жыл бұрын
Bro had 4K quality uploaded, yet I watched entire video(up till tips section) in 360P without even noticing it💀
@bronzebond4869
@bronzebond4869 3 жыл бұрын
Very surprised to see you have less than 2k subscribers. The size of the following subscribers definitely doesnt note the quality of the content. Thanks for explaining the pseudo code and constraints so well. You've got a new subscriber here
@QuanticDev
@QuanticDev 3 жыл бұрын
My pleasure. Blogging/vlogging is always like this. It starts very slowly and eventually takes off.
@PeterParker-sy9bp
@PeterParker-sy9bp 4 жыл бұрын
Hello @QuanticDev, thank you for the tips. There is one thing I noticed, in the last question where you're searching for the substring in a larger string, you said that Space Compx was O(1) but in your code, you are creating a hashmap of characters to their occurrrence counts. So it actually uses O(m) space where "m" is the number of distinct chars in substring. Just wanted to point that out ve video için tekrardan teşekkür ederim :).
@QuanticDev
@QuanticDev 4 жыл бұрын
You are right on point Pete! Space complexity is O(m). Initially I wrote an O(1) solution but time complexity of that was much higher so I traded some memory for efficiency, and forgot to fix the presentation. Good catch!
@siddhantsharma7369
@siddhantsharma7369 4 жыл бұрын
Sir this was a really helpful video providing deep insight of this technique..It would be really beneficial for me if you can make a video on kadene's algorithm and it's variations that can be asked in technical Interviews
@QuanticDev
@QuanticDev 4 жыл бұрын
I will do it next month. Good luck in the interviews.
@abdullahshoukat7848
@abdullahshoukat7848 11 ай бұрын
thank you so much. you deserve much more subscribers and views.
@vanshajsharma3306
@vanshajsharma3306 3 жыл бұрын
that was best 28 minutes of my day
@JamesBrodski
@JamesBrodski 3 жыл бұрын
Thank you so much for making this video! This is beautifully explained.
@shreelakshmi6890
@shreelakshmi6890 3 жыл бұрын
Very good way of explaining the concept and the problems...It helped a lot! Keep it up!
@aliadel1723
@aliadel1723 2 ай бұрын
Awesome we need more videos like this for backtracking and prefix sum etc
@munemadil443
@munemadil443 5 ай бұрын
Great video! One question, why is the space complexity in question 1 constant? For question 2, you said in the worst case we are storing n-windows which makes sense. But aren't we storing n/2 windows in question 1 which by asymptotic equivalence is O(n)?
@nithinthota96
@nithinthota96 7 күн бұрын
Great Explanation!
@tvnathreviews
@tvnathreviews 2 жыл бұрын
14:37 If you have watched FRIENDS 😁 Great video, thanks...
@souravde6116
@souravde6116 2 жыл бұрын
In that example of finding the maximum sum of subarray, I did not find any difference you did between brute force approach and sliding window concept except for one you write it on the bottom and for later you write it on top.
@kaushik.aryan04
@kaushik.aryan04 Жыл бұрын
wow you really explained it very well and fast too just what I was looking for
@slavaslava9763
@slavaslava9763 8 ай бұрын
I think there is mistake in Question 2 - Kardane's algorithm used for finding maximum number, not exact number.
@priyankareddy7408
@priyankareddy7408 3 жыл бұрын
Great content. Thanks for explaining so well. Pls upload more algorithm questions.
@QuanticDev
@QuanticDev 3 жыл бұрын
No worries, I have a ton of upcoming Google/Facebook interview questions.
@teqwonnorman3588
@teqwonnorman3588 2 жыл бұрын
I noticed a mistake with the 3rd problem at 16:55. The target sum was 5 but you said the entire array was the first subarray but the entire array added up to 6, and you started shrinking the array getting the next subarray of (3,2) but i got a subarray of (0,5) instead.
@shaileshkaiwart7190
@shaileshkaiwart7190 2 жыл бұрын
Why are you not making more videos on algorithm?? Your videos are very very very helpful in understanding an algorithm and its variations. Please make more videos. These kind of videos are not present in youtube.
@jasper5016
@jasper5016 Жыл бұрын
Fantastic, wish you could have shown Java code to represent how to think through code. Thanks again
@shivamlokhande4856
@shivamlokhande4856 2 жыл бұрын
at 17:30 , I didn't understand - what do we have to do after adding a positive number
@michaelsundarev5818
@michaelsundarev5818 3 жыл бұрын
Thank you. Very easy to understand video.
@imaginecodes2382
@imaginecodes2382 Жыл бұрын
22:00 i know for this given ip array there will one answer but lets suppose i took an diff ip array like [0,1,0,1,0,0,0,1,1] , there will a tie.
@kamalkunjapur5383
@kamalkunjapur5383 2 жыл бұрын
Brilliant video. Thank you so much for making such amazing content.
@BoTian
@BoTian 3 жыл бұрын
O(n^2) is quadratic time complexity, not exponential. Exponential would be something like O(2^n)
@QuanticDev
@QuanticDev 3 жыл бұрын
True. I have the correction at the top as a pinned comment but I guess it is harder to see on mobiles. Good catch anyway!
@hengzhang5587
@hengzhang5587 2 жыл бұрын
Very good tutorial with good cases. Thanks.
@vishakamohan5336
@vishakamohan5336 4 жыл бұрын
I have a doubt regarding the first question maximum sum subarray. I don't understand how the time complexity is O(n). I mean we do have a variable for the start and end indices and sliding this window across the array will have a time complexity of O(n) ,but shouldn't we also consider the time complexity for calculating the sum of the elements between the start and end index? Then wouldn't the time complexity result in O(n^2) instead-- ( O(n) for sliding across and a nested loop for the sum,which is again O(n) )? Please clear my doubt .Thanks!
@QuanticDev
@QuanticDev 4 жыл бұрын
No need to recalculate the window sum over and over again. We just keep its current value in memory and add the value of the next element from right, or subtract the leftmost element to move the window. You can see the code for this in GitHub and the link is in the video description.
@vishakamohan5336
@vishakamohan5336 4 жыл бұрын
@@QuanticDev Oh yes. Thank you ! This is a really helpful video, thanks a lot!
@gabrielasalvo7080
@gabrielasalvo7080 8 ай бұрын
Amazing explanation!
@jinny5025
@jinny5025 3 жыл бұрын
I just subscribed your channel. Thanks for the helpful materials :) I'm expecting your upcoming videos already!
@QuanticDev
@QuanticDev 3 жыл бұрын
My pleasure. I'm switching to fully animated algo videos so upcoming ones will be interesting.
@damaroro
@damaroro 2 жыл бұрын
Wow your explain is so good, please do upload more about algorithm to solve code challanges
@deepkakadia5679
@deepkakadia5679 4 жыл бұрын
Great Content, very well explained
@SandeepVarunKoduri
@SandeepVarunKoduri 3 жыл бұрын
You just earned a Sub !! Can we please have Java code samples ?
@QuanticDev
@QuanticDev 3 жыл бұрын
Thanks. It's a good idea given the persistent popularity of Java. But going forward, I will only use pseudocode as it is one universal language that all developers will understand. Otherwise, people get confused about language primitives of specific programming languages. However, if anyone contributes a solutions in other languages, I will put them on GitHub next to other solutions.
@codingwithanonymous890
@codingwithanonymous890 2 жыл бұрын
thanks for the video u have explained very well
@大盗江南
@大盗江南 3 жыл бұрын
thanks buddy, this video is so good.... so much help!
@ayushrawat4825
@ayushrawat4825 2 жыл бұрын
You got me subscribed man! really nice video
@kaushik.aryan04
@kaushik.aryan04 Жыл бұрын
please make more videos on dynammic programming and graphs
@manle4454
@manle4454 2 жыл бұрын
Thanks for this video
@subhadipadhikary270
@subhadipadhikary270 3 жыл бұрын
Make a detailed video/series on DP and backtracking or release a course somewhere else
@viswanathank2551
@viswanathank2551 3 жыл бұрын
Good job bud
@yehudacorsia3323
@yehudacorsia3323 4 жыл бұрын
Thank you! its a great video :-)
@mukarramhaq3663
@mukarramhaq3663 4 жыл бұрын
Amazing video! You just earned a sub ! :)
@AccerAspire
@AccerAspire Жыл бұрын
Thank you sir
@shohanur_rifat
@shohanur_rifat 3 жыл бұрын
Subscribed
@lordmoriartea7799
@lordmoriartea7799 3 жыл бұрын
can we use this in python?
@QuanticDev
@QuanticDev 3 жыл бұрын
Of course
@huyvole9724
@huyvole9724 4 жыл бұрын
We need algorithm sliding windows.
@QuanticDev
@QuanticDev 4 жыл бұрын
Link to it is in the video description.
@huyvole9724
@huyvole9724 4 жыл бұрын
@@QuanticDev you need using algorithm process loss package
@huyvole9724
@huyvole9724 4 жыл бұрын
@@QuanticDev arq, ...
@chuongnguyennguyen2227
@chuongnguyennguyen2227 3 жыл бұрын
hi
@nono-qv4um
@nono-qv4um 2 жыл бұрын
teoman 4. soruyu da mulakatta sorarlarsa birakir giderim kardesim
@QuanticDev
@QuanticDev Жыл бұрын
Heh, no no, that's my exaggeration. It could be in a senior CS course final though.
@mehdi-vl5nn
@mehdi-vl5nn 4 ай бұрын
Damn, the video is too old. I hope you see this comment. I wonder what the difference is between an algorithm and a technique?
@rudranarayansamal4168
@rudranarayansamal4168 Жыл бұрын
Great Video ! Thanks for the detailed explanation
@tythedev9582
@tythedev9582 2 жыл бұрын
This is perfect. Thank you. Subbed
Sliding Window Technique - Algorithmic Mental Models
36:45
Ryan Schachte
Рет қаралды 363 М.
FOREVER BUNNY
00:14
Natan por Aí
Рет қаралды 31 МЛН
كم بصير عمركم عام ٢٠٢٥😍 #shorts #hasanandnour
00:27
hasan and nour shorts
Рет қаралды 11 МЛН
If people acted like cats 🙀😹 LeoNata family #shorts
00:22
LeoNata Family
Рет қаралды 23 МЛН
Players vs Pitch 🤯
00:26
LE FOOT EN VIDÉO
Рет қаралды 138 МЛН
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 303 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 586 М.
L12. Minimum Window Substring | 2 Pointers and Sliding Window Playlist
27:06
Sliding Window Leetcode Problem Solved with JavaScript
15:01
James Q Quick
Рет қаралды 8 М.
Sliding Window Technique | Google Coding Interview | Maximum Size SubArray Of Size K
16:06
JAVAAID - Coding Interview Preparation
Рет қаралды 66 М.
Kadane's Algorithm and Its Proof - Max/Min Sum Subarray Problem
19:14
Sliding Window Technique
6:18
Profound Academy
Рет қаралды 14 М.
Sliding Window Maximum | Leetcode
20:16
take U forward
Рет қаралды 263 М.
FOREVER BUNNY
00:14
Natan por Aí
Рет қаралды 31 МЛН