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

2024 ж. 13 Мам.
42 224 Рет қаралды

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

    @RiteshSingh-uz2qs@RiteshSingh-uz2qs2 жыл бұрын
  • 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@juicio_den8 ай бұрын
  • This code is clean and makes so much sense. Thank you for sharing!

    @HR-pz7ts@HR-pz7ts10 ай бұрын
  • Thank you very much. Very descriptive video!

    @uknow2908@uknow29082 жыл бұрын
  • thank you so much sir Such a great and simple way of explanation

    @surya.r3463@surya.r34632 ай бұрын
  • nice visualisation and great technique with binary search

    @rajatsharma6597@rajatsharma65973 ай бұрын
  • This was very well explained, thanks!

    @yankomirov4290@yankomirov429023 күн бұрын
  • Great one

    @gunahawk6893@gunahawk68932 жыл бұрын
  • Thanks!, Logré resolver el problema de los contenedores de agua luego de ver su video.

    @marioprado8789@marioprado878910 ай бұрын
  • Thank you! It helps!😊

    @omj7113@omj71132 ай бұрын
  • Hi. What software do you use for these visualizations? It looks a lot like 3blue1brown's

    @ajmdz@ajmdz Жыл бұрын
    • It's manim, a python library

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

    @12371eric@12371eric5 ай бұрын
    • That's how the leetcode question is worded.

      @bocbinsgames6745@bocbinsgames67455 ай бұрын
  • Can you go topological sort next?

    @davidtran7609@davidtran76093 жыл бұрын
    • Thanks for the suggestion! You'll be happy to know that it is in the backlog of topics that we will cover in the future!

      @JoshsDevBox@JoshsDevBox3 жыл бұрын
  • It will work only for unique elements

    @Nani-cf3sw@Nani-cf3sw2 жыл бұрын
  • O(N) is not > than O(N Log n)

    @zacherywagner1189@zacherywagner11893 күн бұрын
  • 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

    @louievasquez6009@louievasquez6009 Жыл бұрын
    • I was really confused too. The problem has a note "Your returned answers (both index1 and index2) are not zero-based." so I think they're adding 1 to account for this note. It's a weird note, though.

      @Meeko1123@Meeko1123 Жыл бұрын
    • Yes, it’s atypical in my experience to request an answer in index form but also want it non zero. Makes me raise my eyebrow and wonder why add that extra layer.

      @fredirecko@fredirecko Жыл бұрын
    • @@Meeko1123 yup look at the first example. [1,2] was the answer

      @aadhuu@aadhuu11 ай бұрын
  • 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

    @Frizen88@Frizen883 ай бұрын
    • Yes

      @pascal9814@pascal981415 күн бұрын
KZhead