How to Use the Two Pointer Technique

2024 ж. 27 Сәу.
80 733 Рет қаралды

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...

Пікірлер
  • So glad I ran into your channel; your way of making concepts visually understandable is a skill in its own right.

    @brayancuenca6925@brayancuenca69256 ай бұрын
  • 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!!!

    @charlesopuoro5295@charlesopuoro5295 Жыл бұрын
  • loved the video! thanks for helping me understand this better

    @matthewrodriguez3377@matthewrodriguez33773 жыл бұрын
  • 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.

    @erichepperlewp@erichepperlewp Жыл бұрын
  • Absolutely excellent explanations. Thank you!

    @alex_georgescu@alex_georgescu5 ай бұрын
  • Amazing explanation, very clean and concise. Keep up the great work!

    @bebo5619@bebo5619 Жыл бұрын
    • BANANA

      @jensmalzer6344@jensmalzer6344 Жыл бұрын
  • You are an amazing teacher thanks for this

    @iceyyeah@iceyyeah3 ай бұрын
  • thank you my brother this is a really good tutorial!

    @Rob-J-BJJ@Rob-J-BJJ Жыл бұрын
  • 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?

    @siddharthmitra2924@siddharthmitra29249 ай бұрын
  • 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?

    @asadabbas5711@asadabbas57118 ай бұрын
  • If you cant explain it to a 3rd grade student then you dont understand it. This guy gets it! Great tutorial!

    @lborate3543@lborate3543Ай бұрын
  • Great Work!!!

    @julian3231@julian32319 ай бұрын
  • Great video

    @uzochukwu1556@uzochukwu15566 ай бұрын
  • Commenting for the algorithm, goodjob!

    @tyronemiguelarollado1150@tyronemiguelarollado11506 ай бұрын
  • Thank you really you are so helpful instant subscribe

    @jimjim3979@jimjim3979 Жыл бұрын
  • Great video and example thank you

    @serverhunter@serverhunterАй бұрын
  • 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?

    @LM_1010@LM_10102 жыл бұрын
  • awesome video.

    @mmm-ie5ws@mmm-ie5wsАй бұрын
  • Nice content!

    @hiagomachado5792@hiagomachado57923 ай бұрын
  • How can you assume the array is ascending if you just increased or decrease

    @markarmstrong8659@markarmstrong86592 жыл бұрын
  • Your 1000th Sub !!

    @gnanaprakashm843@gnanaprakashm843 Жыл бұрын
  • So for the first example the two sum, would this one only applied to sorted array?

    @lucassmith6320@lucassmith6320 Жыл бұрын
    • yes, because the elif sum < targetValue: pointerOne += 1 will not work on an unsorted array

      @abz4852@abz4852 Жыл бұрын
  • two pointers only work ,if it is a sorted array

    @shashankl8589@shashankl8589 Жыл бұрын
    • yup

      @General_Aladeen@General_Aladeen7 ай бұрын
    • exactly!

      @Mahmoudpd@Mahmoudpd2 ай бұрын
  • Awesome!

    @wence0x076@wence0x076 Жыл бұрын
  • Thank u so much.

    @mohamedhussien4013@mohamedhussien401311 ай бұрын
  • 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?

    @mdouet@mdouet3 жыл бұрын
    • 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

      @realcandadatamil5785@realcandadatamil57853 жыл бұрын
  • is there any reason why the while loop condition cant be while the sum of the two pointers != target ?

    @bananaboydan3642@bananaboydan36429 ай бұрын
    • You aren’t guaranteed to find the sum in the input array so using that loop condition may result in an infinite loop.

      @MagicTre123@MagicTre123Ай бұрын
  • gave you a follow brah

    @haroldtran7848@haroldtran78483 ай бұрын
  • Does two pointer technique requires the array to be sorted?

    @sntshkmr60@sntshkmr602 жыл бұрын
    • 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.

      @Japan2is4awesome@Japan2is4awesome2 жыл бұрын
  • i love you

    @Regalman@Regalman2 жыл бұрын
  • I am not smart enough to do this. I tried for 1 hour. Do not understand the results.

    @Human_Evolution-@Human_Evolution-2 жыл бұрын
  • stop explaining the theory and get into the practical syntax because none of this works

    @owenwu7995@owenwu7995 Жыл бұрын
  • Great video

    @abhrajitray951@abhrajitray951Ай бұрын
KZhead