Visual introduction Two Pointer Algorithm | Data Structure and Algorithm for Coding Interviews

preview_player
Показать описание
We have explained two pointer technique which is the optimal way to solve problems related to arrays in O(N) time. We will start with a brute force solution from O(N^2) to an optimal O(N).
Рекомендации по теме
Комментарии
Автор

The best part of this video is showing how to identify where to apply it. Great Explanation overall

Sailgodgreenearth
Автор

Thanks for explaining perfectly. You were talking about asking the interviewer or using another ds. I came up with another solution, especially if it’s not sorted it’s technically O(n) . You convert the array to an object/hash map, you map the number to index and then loop over the array, you minus the target from the number at array index where your loop is currently at, you try to get if you can then return the indexes. It’s O(n+n) which is 0(n). But two pointers is totally better

juicio_den
Автор

Thanks for the video. I enjoyed the explanation. My only recommendation would be for you to run the coding example in an IDE using the debugger. It would be easier to visualize each step of the algorithm since the operations would appear on screen.

brianwsmithers
Автор

This was the best explanation for me, understanding to approach a problem and optimising it later is the key, Thank you for showing the application on solution very helpful, subbed

aditya
Автор

This code is clean and makes so much sense. Thank you for sharing!

HR-pzts
Автор

nice visualisation and great technique with binary search

rajatsharma
Автор

thank you so much sir
Such a great and simple way of explanation

surya.r
Автор

This was very well explained, thanks!

yankomirov
Автор

Thanks!, Logré resolver el problema de los contenedores de agua luego de ver su video.

marioprado
Автор

Thank you very much. Very descriptive video!

uknow
Автор

the rum time animation in 4:37 is not accurate
shouldn't move the front pointer until the current sum is smaller then target, as your code says. but nice video, thanks

Frizen
Автор

I'm fairly new to this concept, I understand that you return an array of size 2 with the current index locations of the 2 values that equal our sum. However, I don't understand why you add one to these indexes? I solved this problem in Java and adding one to the indexes returned the wrong value. Is this just how the language you are using functions?

eric
Автор

Hi. What software do you use for these visualizations? It looks a lot like 3blue1brown's

ajmdz
Автор

when returning the two indicies, why add 1 to both? 2 and 7 were at indexes 0 and 1 respectively so confused why you have to add the 1

louievasquez