LeetCode Exercise in Java Tutorial - Two Sum FAST Solution

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ส.ค. 2024

ความคิดเห็น • 457

  • @danielaviv8215
    @danielaviv8215 2 ปีที่แล้ว +307

    Please do this kind of videos more!

  • @BlazingStar2001
    @BlazingStar2001 2 ปีที่แล้ว +184

    Doing more these kinds of things is very helpful, especially how u approach them. Teachers normally tell us the optimal solution but how to get to that or how to come up with that solution is not normally taught to us.

  • @manosmakris8308
    @manosmakris8308 2 ปีที่แล้ว +83

    Do more of these kind of videos because your thought process make me think in a different way than before.

  • @omarkabada2923
    @omarkabada2923 2 ปีที่แล้ว +25

    Yes, more videos like this would be amazing because you don't only solve the challenges, but explain the thinking behind it.

    • @MohitKhare
      @MohitKhare 11 หลายเดือนก่อน

      well said sir ! Even I can understand the concepts quite easily and I'm not a native english speaker.

  • @memesv3.093
    @memesv3.093 2 ปีที่แล้ว +23

    Thanks a lot John. Please start a Leetcode series, your way of explanation is flawless

  • @wadebrumbaugh7579
    @wadebrumbaugh7579 ปีที่แล้ว +5

    I thought of your initial solution right away but would have NEVER thought of the better way. These types of videos are EXTREMELY helpful in reprogramming the way I look at a problem. Thank you!!

    • @maaax573
      @maaax573 8 หลายเดือนก่อน

      Comments like this help me understand that its ok that I couldnt come up with that second solution on my own. Thank you.

  • @Riv3rt
    @Riv3rt 2 ปีที่แล้ว +54

    Love these algorithm video's personally, keep'em coming! Of course all your tutorials are also awesome- so I guess just keep up the good work!

  • @zoflax
    @zoflax 2 ปีที่แล้ว +10

    honestly a weekly leetcode video like this would be so good. Please do more!

  • @RizwanAli-by4nl
    @RizwanAli-by4nl 2 ปีที่แล้ว +6

    Please do this kind of videos.
    It helps alot to understand the problem

  • @GuessWhos
    @GuessWhos 2 ปีที่แล้ว +7

    Please, keep doing this leetcode content. There is not good leetcode videos in Java, so this is gold!

  • @christianolsson8644
    @christianolsson8644 2 ปีที่แล้ว +5

    I definitely want more videos like this! You're an excellent teacher. I'm trying to get a job as a Java developer and I'm freshening up my knowledge. I will always come back to your videos. They are fun, interesting topics, easy explained and very helpful! 😃

    • @user-uu3us9ys4q
      @user-uu3us9ys4q 2 ปีที่แล้ว

      If you struggle with finding a first job, try to look for testers, then get to automate tester, then you will be a perfect java coder because you know how stuff should work.
      Requirements for junior tester are so little, it is easy to apply

  • @joryroberts2518
    @joryroberts2518 2 ปีที่แล้ว +7

    More of these types of videos would be fantastic! Your explanations throughout all of your videos are incredible, and I just started tackling coding challenges and I've been struggling with how to even begin. Appreciate your channel so much!

  • @MatthewWeiler1984
    @MatthewWeiler1984 2 ปีที่แล้ว +7

    Great solution.
    You can decrease the memory footprint by not bothering storing the complement/index of values that are greater than the target as those would require negative numbers to achieve the target.

    • @tonypsilon_gaming3221
      @tonypsilon_gaming3221 2 ปีที่แล้ว +4

      Well, the problems only states integers, so they might as well be negative, or?

    • @MatthewWeiler1984
      @MatthewWeiler1984 2 ปีที่แล้ว +1

      @@tonypsilon_gaming3221 Fair enough.
      But 1 question that I would ask is if negative numbers are possible in the source array.
      But since this is an online test, which can be submitted multiple times, I'd assume as much and run my answer to see if it fails any test cases... If it passes all test cases, then I would add a comment explaining the optimization.

  • @soniahandle
    @soniahandle ปีที่แล้ว +1

    A playlist with videos like this would be phenomenal! Thank you for sharing these with us!

  • @user-jn2rs3rw3x
    @user-jn2rs3rw3x 2 ปีที่แล้ว +3

    We want more leetcode questions! you're an expert in teaching. Thanks a lot.

  • @tangobee
    @tangobee 2 ปีที่แล้ว +1

    really this is soo awesome because i just started doing leetcode and i wanted someone who can guide me and here you are like a angel :D

  • @stefans6557
    @stefans6557 ปีที่แล้ว +1

    From what I know first solution is: O(n*(n-1)/2) and for the outer loop you should do: for (int i = 0; i < nums.length - 1; i++)
    Of course it still can be simplified to O(n²) - but never really understand why. I mean it's quadratic, but still quite a reasonable difference to loop i and j from 0 to end. (about half the time of O(n²), which I think is still a difference, especially if it is longer, like from 20 mins to 10 mins)

  • @anthony68759
    @anthony68759 2 ปีที่แล้ว +2

    All of your videos have been so incredibly helpful to a career changing CS student like myself! Leetcode has always seemed super intimidating but your teaching style really makes them seem doable. Please do more like this!

  • @nabeelrehman5451
    @nabeelrehman5451 2 ปีที่แล้ว +1

    Was just solving this problem and your video came in. Thanks and would love to watch more videos on leet code problems.

  • @sarojmaharjan3986
    @sarojmaharjan3986 2 ปีที่แล้ว +4

    Wow do more of these videos ! Love your explanation

  • @SailBuddha
    @SailBuddha 2 ปีที่แล้ว +2

    Never thought about a solution like that before. This is a very useful tool to add to the tool box. Thanks!

  • @debasishpradhan9951
    @debasishpradhan9951 2 ปีที่แล้ว +4

    Hi John , waiting for the next episode , it will really help to broaden the logical thinking .
    I'm a java developer, but never imagined hashmap can be used in such a way.

  • @musaddiqmanzoor2044
    @musaddiqmanzoor2044 2 ปีที่แล้ว +1

    I've to advocate that we do need more such stuff, @John.

  • @micleh
    @micleh 2 ปีที่แล้ว +1

    In order to create a stash of solutions to common problems, I'd love to see more of such videos, taught by someone who really knows what he's doing and who can teach in a clear and straightforward manner. Thanks for sharing this knowledge.

  • @santiagoaristi2808
    @santiagoaristi2808 ปีที่แล้ว +1

    Thank you John for taking the time in creating this video! Please do more of these videos as it teaches problem solving skills and how to walk through the creation of an algorithm. Thanks!

  • @jaseembinmuhammed5861
    @jaseembinmuhammed5861 ปีที่แล้ว +1

    Great solution!
    One small thing, i think we can reduce the runtime to 1ms by calculating list size out side the loop and do the iteration on calculated size ,otherwise, in each iteration in the loop java will take sime time to calculate the array size
    int size= nums.length;
    map=.....
    for (int i = 0; i < size; i++) {
    ....
    }

  • @santhoshkumar7285
    @santhoshkumar7285 2 ปีที่แล้ว +3

    Do a lot more videos like this!!! I love The way you explain it, keep doing this

  • @TheNameIsAdmiral
    @TheNameIsAdmiral ปีที่แล้ว +2

    One of the best coding channels. VERY well explained. Cheers! You deserve way more subs.

  • @mohsenrezaee9936
    @mohsenrezaee9936 ปีที่แล้ว

    That thing you said at the end... That makes me feel so much better about myself. I used to feel like there's something wrong with me, but it's natural, apparently!

  • @hinocenciopaulo
    @hinocenciopaulo 2 ปีที่แล้ว +2

    Dude!! Thanks a lot for this video!! I was straggling with this same question in the AlgoExpert, and I couldn’t understood the Clément's explanation. You explained SO MUCH better, and for free... Please launch a course of Algorithms and Data Structure. I'll definitely pay for that.

  • @Michaelpschreib
    @Michaelpschreib 7 หลายเดือนก่อน

    As a mostly self taught dev, I really appreciate your content. It has helped me grasp concepts I've been struggling with for a very long time. Thank you!!

  • @javo_rocker
    @javo_rocker 2 ปีที่แล้ว +3

    That's a great video! I had had struggle finding a solution for that kind of problems and that helps a lot. Thank you so much!

  • @JRC.40.31
    @JRC.40.31 3 หลายเดือนก่อน

    It took me a week to "sink in " but I solved my first leetcode with this video , thanks God this video Exist and Thank you John for creating such an amazing video .

  • @NandanChhabra91
    @NandanChhabra91 2 ปีที่แล้ว +1

    Thank you for covering such problems and that too in detail. We usually don't get such insights when doing things alone. Please park some time for adding such videos regularly. Thank you

  • @chair_force
    @chair_force 2 ปีที่แล้ว +45

    Yes more leet code/algo videos, there’s barely any good Java leet code videos on TH-cam. Mostly just python and JavaScript videos. Java is neglected on leet code.

  • @neeldiyora3575
    @neeldiyora3575 ปีที่แล้ว +1

    I'm new to this channal. Before I saw this video I don't knew what is really hashmap is but after seeing this..... Nothing to say.
    This video is really helpful.
    Thank's for creating this awesome video.

  • @Bladebreak3r
    @Bladebreak3r 4 วันที่ผ่านมา

    Thanks for the encouragement at the end. My solution is close but not quite optimal. It's O(n) space complexity but O(2n) time complexity. I felt bad about not thinking about the hashmap solution until you gave your encouraging words at the end! Thanks man 🥺

  • @richardmeyer418
    @richardmeyer418 2 ปีที่แล้ว +2

    Thank you. This was super interesting (to me, anyway). Please give us a few of these every now and then - I'm not asking you to make it exclusive, but it was fun.

  • @oleksandrkardash4898
    @oleksandrkardash4898 7 หลายเดือนก่อน

    please make more of these exercises! This is a good way to learn and practice coding

  • @akshaynile2778
    @akshaynile2778 2 ปีที่แล้ว +2

    Wow !
    Really a brilliant solution using a Map. 😇
    Thanks for this video John. I learnt a new technique today. 👍

  • @harika2988
    @harika2988 2 หลายเดือนก่อน

    Really like the way you have presented the logic and would like to see more of these kind of videos.

  • @jatinkumar7287
    @jatinkumar7287 2 ปีที่แล้ว +1

    Plz do this more often I'm learning java so it's very helpful on how to approach leetcode problems. Thanks.

  • @andreuzamurengera848
    @andreuzamurengera848 2 ปีที่แล้ว +2

    This solution is amazing. We would love to see more questions of this complexity

  • @a1esandra
    @a1esandra ปีที่แล้ว

    I really needed to hear that last bit in the end. im a 2nd yr cs student and ab to do my first technical test for an internship n i find them very hard and even thought of dropping out lol. so thank you

  • @martinnnachi
    @martinnnachi 2 ปีที่แล้ว +1

    Would definitely like to see more challenges! Never would've thought about using a hashmap and like you said, one more thing I've learnt. Thanks a million. You're a great teacher!

  • @kareemlateefyomi8690
    @kareemlateefyomi8690 3 หลายเดือนก่อน

    Thanks John, this puts a smile on my face. Hope to see more of this

  • @applemaysl
    @applemaysl ปีที่แล้ว +1

    Can you please do more of these? Your explanation was so clear and to the point, I wish there was more!

  • @pejko89
    @pejko89 2 ปีที่แล้ว +2

    Simply amazing channel. Gives me so much confidence to keep learning and not to give up.

  • @narenm.s8923
    @narenm.s8923 2 ปีที่แล้ว

    Please do these kind of videos.. because of your great explanation about hashmap now i understood it.. Before i know what is a map, set but i don't know how they actually work..now i know
    Thankyou

  • @esmelealemmihretu941
    @esmelealemmihretu941 2 ปีที่แล้ว +1

    Please we need such kind more questions! Appreciated!

  • @gurudattshahane
    @gurudattshahane 2 ปีที่แล้ว +1

    Please make more videos like this, your explanation is just amazing💞. I am grateful to have people like you delivering high quality content free 🙏🙏🙏

  • @kevin_mitchell
    @kevin_mitchell หลายเดือนก่อน

    9:44 The solution will return [2, 2] for a target off 8 which is incorrect since the same element is used twice.
    The code for the "i" should be for (int i = 0; i < nums.length - 1; i++) {...} For the i, j loop version.

  • @EstrellasBakery
    @EstrellasBakery ปีที่แล้ว

    I really appreciate the message you start to give at 21:57 - I have been feeling very discouraged as of late trying to sharpen my problem solving skills and it was very comforting to hear that. Thank you!

  • @hassansiddiqui8231
    @hassansiddiqui8231 ปีที่แล้ว

    I have to agree with the majority of the other comments - your explanations of algorithms for solving LeetCode solutions (well, in general good software algorithms) are some of the clearest I've seen. This is probably going to be a new subcategory of videos that you might not have planned to do, but I can see there's so much interest you have no choice but to do them! (Please?)

  • @lanatimmo3686
    @lanatimmo3686 ปีที่แล้ว +1

    Thanks a lot for this clear explanation! Please, do more tutorials for LeetCode exercises!🙏

  • @amaralensheriff
    @amaralensheriff ปีที่แล้ว

    I had to rewatch the last section as you suggested to finally get it, thanks again John. You are the man.

  • @pliegosevilla
    @pliegosevilla 2 ปีที่แล้ว +1

    Im so grateful you are doing this.
    You are one amazing teacher. It’s so easy to understand code with your explanations.
    Very very grateful.

  • @upzaiz8095
    @upzaiz8095 2 ปีที่แล้ว

    Yes.. Nice. Coding is not just getting the correct result. But it also getting the result in correct/optimal way. Please deliver this type of videos which really brain storm and change the thinking way of coding.

  • @ibrahimwadi6539
    @ibrahimwadi6539 2 ปีที่แล้ว +1

    OMG!!!!! man how can you be so good at teaching ??? you just made my day. please keep the videos coming 🙂

  • @fojirngers3661
    @fojirngers3661 ปีที่แล้ว

    I don't get it, why people don't subscribe and like this guy's channel and videos. He is the best.

  • @auniquehandle
    @auniquehandle 2 ปีที่แล้ว +1

    Hi John, i love this video. Learning algo on Leetcode is hard even with looking at the solution. However this video helped me understand 2 sum very easily. Thank you

  • @UTJunaid
    @UTJunaid 2 ปีที่แล้ว

    Please do this kind of video more and more! your explanation is so easy to understand. I got the concept in the first watch only.

  • @Andboldquates
    @Andboldquates ปีที่แล้ว

    thank you solving problem with deep details, we having mostly trouble to understand , the way how you explain is highly catchable

  • @mehmetakif8639
    @mehmetakif8639 2 ปีที่แล้ว

    Well, i think i can watch these kind of videos whole day without getting bored. Well done. Just perfect.

  • @sdors4
    @sdors4 2 ปีที่แล้ว

    You have a brilliant mind, that’s so simple solution and very smart

  • @randomname6444
    @randomname6444 10 หลายเดือนก่อน

    This did kind of blow my mind ngl.
    I would've never thought of this solution to the problem.
    Now I wonder where else this method might be applicable.

  • @minakianrad812
    @minakianrad812 ปีที่แล้ว

    Thank you for this video. Please do more of the Leetcode problems. Thank you.

  • @UHealthyLife
    @UHealthyLife 6 หลายเดือนก่อน

    please do more videos like this. your channel is more helpful for beginners too.

  • @shariefrana
    @shariefrana 7 หลายเดือนก่อน

    Love the way you teach and present the content in most simplest way, It would be great to see DSA and System design courses from you.

  • @sultangaddafi8698
    @sultangaddafi8698 ปีที่แล้ว

    I was stuck for hours looking on how to write the first line of code on such leetcode problems....leetcode can be intimidating but thanks for such content, it really helps!!....please do more especially in java

  • @Molotom
    @Molotom 2 ปีที่แล้ว +1

    Great video, John! What sets you apart is that you have a very clear communication style, and you're very encouraging as well. I think that this LeetCode video showcases those skills really well, and it would be awesome if you made more in the future :)

  • @sigfigronath
    @sigfigronath 2 ปีที่แล้ว +1

    Need more videos like this John 😋

  • @DevSofo
    @DevSofo ปีที่แล้ว +1

    So happy i found your channel...😎 premium value ✌️✌️✌️

  • @rajwanahmed935
    @rajwanahmed935 2 ปีที่แล้ว +1

    First thanks for the video. Please do this kind of video more! It's helped me a lot.

  • @WealthyFrog
    @WealthyFrog ปีที่แล้ว

    you are awesome man! You've given me a new way to face problems like these! Thank you.

  • @grimsri3782
    @grimsri3782 2 ปีที่แล้ว +1

    Please post this kind of videos more. I like the way you explaining the details by going into the deep. I am waiting😋

  • @andrewchang7194
    @andrewchang7194 2 ปีที่แล้ว

    Two sum was my first experience to how useful hash maps were. Started using them in all tasks where you need to look at every unique element of an array.

  • @Raied114
    @Raied114 ปีที่แล้ว

    I'd love to see more videos about what you talked about at the last min of the video: "I never would have thought of that!".
    Your way of explaining the thought process is exactly what I'm looking for in these types of videos. I don't just want to see the solution to this or that coding problem, but the idea behind it.
    Please keep them coming!

  • @tfamidoinglol4243
    @tfamidoinglol4243 2 ปีที่แล้ว

    Please make more of these videos. This video was very well explained.

  • @davidx5828
    @davidx5828 2 ปีที่แล้ว +2

    Really good video, explaining the code was in-depth and at an appropriate level. Maybe a video on the time/space complexity? That was a hard concept for me starting out.

  • @MohitKhare
    @MohitKhare 11 หลายเดือนก่อน

    My freaking God John, that was the best explanation I've found so far on the internet. Sure there could be more ways but the fact that you are able to explain it so easily and also the way you communicate as a speaker is remarkable.
    Keep doing what you do buddy, and thanks a lot. ❤ from INDIA. I feel blessed that we have people like you working with JAVA.

  • @jvjohn
    @jvjohn 2 ปีที่แล้ว

    Thanks John. This was very helpful. Please keep adding more of these kind of videos.

    • @CodingWithJohn
      @CodingWithJohn  2 ปีที่แล้ว

      Glad it was helpful, I'm planning to!

  • @nanthawatanancharoenpakorn6649
    @nanthawatanancharoenpakorn6649 ปีที่แล้ว

    Please do more. I would like to learn and see how you approach the problem, why you think and how you think.thank you

  • @talk9415
    @talk9415 2 ปีที่แล้ว +1

    please stop, you have some very good java vids, super useful. for any leetcode question you can find million solutions.

  • @ThinkScienceCanada
    @ThinkScienceCanada 7 หลายเดือนก่อน

    this video is amazing!! thanks for all the explanation, please continue with this! Im using java to do these code challenges and your videos helps me a lot

  • @kingjames8723
    @kingjames8723 2 ปีที่แล้ว +2

    Hey John,
    Thanks so much for your videos they have being really helpful to my java knowledge.
    I would love to see more videos from you on Arrays, OOP and Real life application of Arrays and OOP.
    Thanks a million.
    Big thumb 👍

  • @dele1518
    @dele1518 2 ปีที่แล้ว +1

    Please do more like this. this is really awesome

  • @rafaelmarcos9733
    @rafaelmarcos9733 6 หลายเดือนก่อน

    Thank you, I was struggling on how to optimize my solution in C using just One for loop.

  • @killer4virus
    @killer4virus 2 ปีที่แล้ว +1

    Amazing!! I started enjoying java due to your videos :)

  • @SrikanthNalla17
    @SrikanthNalla17 ปีที่แล้ว +1

    Yes
    Please add more videos of leetcode problems

  • @nandhurix9547
    @nandhurix9547 8 หลายเดือนก่อน

    Hi John, the way you explained is more clear and more precise so I suggest you do this kind of video more and make it a playlist for Leetcode easy problems, People who are new to Leetcode like me would appreciate more content like this.

  • @ShakilaBoler-wz1os
    @ShakilaBoler-wz1os ปีที่แล้ว

    Hey John please do more leetcode videos. I love how clear and precise your explanations are!! I was sad to only see the two videos in the playlist. Hope you’re doing great!!

  • @FA-sr6lx
    @FA-sr6lx 2 ปีที่แล้ว

    Thanks for the video. Theres not enough of these out there

  • @theproactivemindset
    @theproactivemindset 6 หลายเดือนก่อน

    Amazing video John, thanks!!! I would love a Java Leetcode series :)

  • @levybuildz
    @levybuildz ปีที่แล้ว

    Just started my Leetcode journey and this was the exact video I needed to feel more confident about trying more problem and being ok about not knowing the best answer or an answer at all. You thoroughly explained 2 ways of solving the Two Sum problem and reassured me that practicing more leetcode will sharpen my eye for finding solutions to coding problems. IMO this is a must watch for all first time leetcoders! Thank you John 🫶

  • @COD_MW007
    @COD_MW007 2 ปีที่แล้ว

    I enjoy each and every bit of thing you do. when you write the code, when you feel something about the code and laugh, I laugh too. you are helping me and others who are just in the path of learning java in the best way possible. Huge respect for you Sir!! you just keep doing what you are doing, I am eager to learn a lot of things from you.

  • @mislam2565
    @mislam2565 5 หลายเดือนก่อน

    Hey John! Thank you so much. Your simplifications make it so much easier. keep going and keep growing.

    • @user-mh7bq5gx9c
      @user-mh7bq5gx9c 4 หลายเดือนก่อน

      I am sorry to disturb you , do you know how he could copy the problem to intillij directly ?

    • @mislam2565
      @mislam2565 4 หลายเดือนก่อน +1

      If you notice, he copies the code from intellijidea and pastes it into the leetcode space after deleting the existing code in the Leet code space. Where do you get the problem?

    • @user-mh7bq5gx9c
      @user-mh7bq5gx9c 4 หลายเดือนก่อน

      @@mislam2565 What i meant was how he could move the problem _at first _to intellij idea , specifically at 3:17 .

    • @mislam2565
      @mislam2565 4 หลายเดือนก่อน +2

      @@user-mh7bq5gx9c He doesn’t show it there, but we need to create new java class, name it ‘Solution’ and then copy the code. Hope it helps

    • @user-mh7bq5gx9c
      @user-mh7bq5gx9c 4 หลายเดือนก่อน +1

      @@mislam2565
      Thanks

  • @sebon11
    @sebon11 ปีที่แล้ว

    Dude this video is brilliant and excellent! Not just the solution, the explanations and the speech at the end as well. Thank you!

  • @davidzurawski4243
    @davidzurawski4243 ปีที่แล้ว +1

    Please do more of these leetcode videos!

    • @CodingWithJohn
      @CodingWithJohn  ปีที่แล้ว

      The most recent video is another one!

  • @aspeno5613
    @aspeno5613 ปีที่แล้ว

    thanks for your thorough explanation of the hash map! I understand it so much better now!