How to Use the Two Pointer Technique

  Рет қаралды 87,670

Team AlgoDaily

Team AlgoDaily

Күн бұрын

The two pointer technique is a near necessity in any software developer's toolkit, especially when it comes to technical interviews. In this guide, we'll cover the basics so that you know when and how to use this technique.
algodaily.com/lessons/using-t...

Пікірлер: 44
@lborate3543
@lborate3543 3 ай бұрын
If you cant explain it to a 3rd grade student then you dont understand it. This guy gets it! Great tutorial!
@solmazkhosravi4355
@solmazkhosravi4355 17 күн бұрын
I don't usually leave comments but your explanation is so on point. Not too much not too little. Well done! I subscribed to the channel just by watching this video
@brayancuenca6925
@brayancuenca6925 8 ай бұрын
So glad I ran into your channel; your way of making concepts visually understandable is a skill in its own right.
@charlesopuoro5295
@charlesopuoro5295 Жыл бұрын
Thank you so much for explaining this concept in a clear manner. It was evident that you made an effort to communicate and impart knowledge. And yeah, I sure did learn. Thanks again for this charitable endeavor. Salute!!!
@matthewrodriguez3377
@matthewrodriguez3377 3 жыл бұрын
loved the video! thanks for helping me understand this better
@soundaryanattuva6559
@soundaryanattuva6559 4 күн бұрын
Such a great explaination!
@asadabbas5711
@asadabbas5711 10 ай бұрын
thankyou for explaining in a very easy manner that even a newbie to programming can understand the problem and its solution pretty well. Although I've two questions regarding the two problem examples you discussed. 1) do two pointer technique on TwoSum only work on a sorted array? I don't see accurate results on unsorted arrays. 2) in your problem # 2, will your solution work on a link list with a cycle hoping for more than 1 node?
@erichepperlewp
@erichepperlewp Жыл бұрын
Good job on your presentation! This helped me understand the basic two-pointer concept. My only suggestion would be to make a linked follow "suggested video" discussing what a "cycle" is. You are referring to this "cycle" as if it is a specific concept or data structure, as opposed to base/generic understanding of a cycle being anything that repeats in circular manner. Saying something like "A cycle in Python [or whatever language this is] is where you ping a database connection multiple times until you get a handshake. This can be the source of many headaches and hard to troubleshoot" ... Something like that. I just made that up, but you would of course give the actual explanation of what you are calling a #cycle AND a quick synopsis of why we care about finding one.
@alex_georgescu
@alex_georgescu 6 ай бұрын
Absolutely excellent explanations. Thank you!
@bebo5619
@bebo5619 Жыл бұрын
Amazing explanation, very clean and concise. Keep up the great work!
@jensmalzer6344
@jensmalzer6344 Жыл бұрын
BANANA
@siddharthmitra2924
@siddharthmitra2924 11 ай бұрын
Great video, thank you for the clear explanation :) My question is regarding using the 'two pointer' technique to check for cycles within the linked list, which you present towards the end of the video. Would using more pointers solve the question faster? So if we used 3 pointers, i.e, pointer 1 has a speed of x, pointer 2 -> 2x and pointer 3 -> 3x would we solve the question faster?
@shashankl8589
@shashankl8589 2 жыл бұрын
two pointers only work ,if it is a sorted array
@General_Aladeen
@General_Aladeen 9 ай бұрын
yup
@MahJohn
@MahJohn 4 ай бұрын
exactly!
@Rob-J-BJJ
@Rob-J-BJJ Жыл бұрын
thank you my brother this is a really good tutorial!
@iceyyeah
@iceyyeah 5 ай бұрын
You are an amazing teacher thanks for this
@julian3231
@julian3231 11 ай бұрын
Great Work!!!
@lucassmith6320
@lucassmith6320 Жыл бұрын
So for the first example the two sum, would this one only applied to sorted array?
@abz4852
@abz4852 Жыл бұрын
yes, because the elif sum < targetValue: pointerOne += 1 will not work on an unsorted array
@jimjim3979
@jimjim3979 Жыл бұрын
Thank you really you are so helpful instant subscribe
@mdouet
@mdouet 3 жыл бұрын
For Two Sum, wouldn't it be fewer loop iterations to use a HashMap to store each element's location in the array, then you could just do the following on each loop iteration: 1. Get the difference between the current value and the target. 2. Check to see if that value is already stored in the HashMap, if it is, we're done, so just return the current index, and the index stored in the HashMap. 3. If it wasn't found in the HashMap, store the current value and the current index in the HashMap for future lookups (see step 2). 4. If we've gone through each element and didn't find a match, there is no match. At worst you would be doing N iterations, it seems the worst case for the Two Pointer approach is greater than N iterations unless I'm missing something?
@realcandadatamil5785
@realcandadatamil5785 3 жыл бұрын
HashMap is also a good solution. But what about the space complexity? We are using a HashMap so it will become O(N). So the two-pointer approach is better than using a compliment hashmap IMKP
@wence0x076
@wence0x076 Жыл бұрын
Awesome!
@markarmstrong8659
@markarmstrong8659 2 жыл бұрын
How can you assume the array is ascending if you just increased or decrease
@tyronemiguelarollado1150
@tyronemiguelarollado1150 8 ай бұрын
Commenting for the algorithm, goodjob!
@serverhunter
@serverhunter 3 ай бұрын
Great video and example thank you
@mohamedhussien4013
@mohamedhussien4013 Жыл бұрын
Thank u so much.
@LM_1010
@LM_1010 2 жыл бұрын
For the fast pointer to go back to node 3, i assume by default node 4 being last node has its "next" pointing to the previous node? Because if not, how will fast.next.next from node 3 move fast pointer back to node 3?
@uzochukwu1556
@uzochukwu1556 8 ай бұрын
Great video
@gnanaprakashm843
@gnanaprakashm843 Жыл бұрын
Your 1000th Sub !!
@mmm-ie5ws
@mmm-ie5ws 3 ай бұрын
awesome video.
@hiagomachado5792
@hiagomachado5792 5 ай бұрын
Nice content!
@bananaboydan3642
@bananaboydan3642 11 ай бұрын
is there any reason why the while loop condition cant be while the sum of the two pointers != target ?
@MagicTre123
@MagicTre123 3 ай бұрын
You aren’t guaranteed to find the sum in the input array so using that loop condition may result in an infinite loop.
@sntshkmr60
@sntshkmr60 2 жыл бұрын
Does two pointer technique requires the array to be sorted?
@Japan2is4awesome
@Japan2is4awesome 2 жыл бұрын
Yes since you can only traverse one way for both pointers and theres an assumption that behind the pointer is either smaller or bigger, depending on where the pointer started.
@BigDataWithSky
@BigDataWithSky Ай бұрын
Yes definitely, it will work only if the array is sorted
@codekiss8888
@codekiss8888 Ай бұрын
The program u showed for solving two sum doesn't work correctly as it fails to pass the second test on the leetcode platform because all combinations are not tried.
@Aspyeater3869
@Aspyeater3869 5 ай бұрын
gave you a follow brah
@Regalman
@Regalman 2 жыл бұрын
i love you
@Human_Evolution-
@Human_Evolution- 2 жыл бұрын
I am not smart enough to do this. I tried for 1 hour. Do not understand the results.
@owenwu7995
@owenwu7995 Жыл бұрын
stop explaining the theory and get into the practical syntax because none of this works
@abhrajitray951
@abhrajitray951 3 ай бұрын
Great video
I Solved 1583 Leetcode Questions  Here's What I Learned
20:37
ThePrimeTime
Рет қаралды 534 М.
3 wheeler new bike fitting
00:19
Ruhul Shorts
Рет қаралды 46 МЛН
Final muy inesperado 🥹
00:48
Juan De Dios Pantoja
Рет қаралды 18 МЛН
ИРИНА КАЙРАТОВНА - АЙДАХАР (БЕКА) [MV]
02:51
ГОСТ ENTERTAINMENT
Рет қаралды 3,1 МЛН
why are switch statements so HECKIN fast?
11:03
Low Level Learning
Рет қаралды 384 М.
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2 МЛН
The Unfair Way I Got Good At LeetCode
23:02
Aman Manazir
Рет қаралды 53 М.
L1. Introduction to Sliding Window and 2 Pointers | Templates | Patterns
36:55
The LeetCode Fallacy
6:08
NeetCode
Рет қаралды 427 М.
10 Math Concepts for Programmers
9:32
Fireship
Рет қаралды 1,8 МЛН
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 254 М.
Two Pointer Algorithm | Two Sum Problem | Solve DS Problems in O(N) Time
19:18
JAVAAID - Coding Interview Preparation
Рет қаралды 107 М.
3 wheeler new bike fitting
00:19
Ruhul Shorts
Рет қаралды 46 МЛН