K Inverse Pairs Array - Leetcode 629 - Python

Sdílet
Vložit
  • čas přidán 27. 07. 2024
  • 🚀 neetcode.io/ - A better way to prepare for Coding Interviews
    🧑‍💼 LinkedIn: / navdeep-singh-3aaa14161
    🐦 Twitter: / neetcode1
    ⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
    Problem Link: leetcode.com/problems/k-inver...
    0:00 - Read the problem
    0:39 - Recursive explanation
    10:36 - Recursive coding
    13:39 - DP explanation
    20:38 - DP coding
    24:47 - Sliding Window explanation
    27:24 - Sliding Window coding
    leetcode 629
    #neetcode #leetcode #python

Komentáře • 342

  • @FirmamentTSW
    @FirmamentTSW Před 6 měsíci +22

    neato!! learned a lot from how you gradually get the final solution.

  • @wintersol9921
    @wintersol9921 Před 6 měsíci +4

    I don't know how you do it, put you always explain just the best and the simplest way possible. CZcams coding community is very lucky to have you, thanks man. I learned a lot from you, both how to code better and how to think to solve :D

  • @BlunderArmour
    @BlunderArmour Před 6 měsíci +2

    Neato!!! Thank you for the explanation! This is definitely one of those problems where it's nearly impossible to come up with a solution in a time bound scenario.

  • @simonvutov7575
    @simonvutov7575 Před 6 měsíci +4

    Neato! This was super well explained and I felt like I came up with it myself and fully understood it by watching your thought process!!

  • @satyamjha68
    @satyamjha68 Před 6 měsíci +13

    Unable to solve on my own !!😭😭 I wrote O(n*n*k) solution but I wasn't able to write O(n*k) approach. Thanks for explanation!!

  • @jonathanlo1026
    @jonathanlo1026 Před 6 měsíci +6

    neato~ I actually watched a chinese youtuber solve this then came to see how you solved it, really loved the detailed explanation thank you, I got a lot from the first brute force dfs as well!

  • @anthonyleong4238
    @anthonyleong4238 Před 6 měsíci +2

    I actually watch these. Algorithms are my passion, but I suck at interviews due to nerves. I am hoping that understanding these super hard problems conceptually by watching these videos can help me complete all medium/lower hard problems.

  • @sachinsinghbhadoriya9523
    @sachinsinghbhadoriya9523 Před 6 měsíci

    Neato! This was one of THE problems I was not able to get my head around! Thanks for all the good work!

  • @user-ue7xt5hv9i
    @user-ue7xt5hv9i Před 6 měsíci

    neato! never have i ever enjoyed watching a leetcode solution this much! The whole process helped me visualize not just this problem but how to approach a dp in general. Thank you!

  • @user-ks7dw5uc6w
    @user-ks7dw5uc6w Před 6 měsíci

    big NEATO! Your solutions have been tremendous! I've been learning to code on my own and reach for this channel whenever I get stumped on a leetcode problem.

  • @SanketBhat7
    @SanketBhat7 Před 6 měsíci +2

    Neato!! As far as knowledge is gained and content is understandable, doesn't matter how long the video is .. Thanks for the video

  • @walkastray007
    @walkastray007 Před 6 měsíci +1

    Its kind of funny because the voice I use in my head for solving problems is your voice.
    Honestly this was a really well put together video. I really enjoyed how you go with brute force solutions and make optimizations one after the other. This really helps since it shows us how to get from a starting point to something finished

  • @rahulsbhatt
    @rahulsbhatt Před 6 měsíci +1

    Thank you so much neato!
    You make these types of videos with so much clarity!
    It really helps me out a lot!
    Thank you so much for the daily content, man!

  • @hamirmahal
    @hamirmahal Před 5 měsíci

    Neat-o! I appreciate the longer length videos. I think they're very helpful. Thank you for making them.

  • @radon3894
    @radon3894 Před 6 měsíci +1

    Another excellent video, appreciate the time to explain your thought process!

  • @abhishekkaintura6398
    @abhishekkaintura6398 Před 6 měsíci

    the way you explain the problem is really appreciable

  • @lawlesslotus
    @lawlesslotus Před 6 měsíci

    neato! thanks for the explanation, I always jump to your channel whenever there's a Hard problem.

  • @aryanikale7187
    @aryanikale7187 Před 6 měsíci +1

    Thank you for this, definitely a hard problem

  • @piyushgupta7210
    @piyushgupta7210 Před 6 měsíci

    neato! thanks man.. you really are making stuff easier for beginners

  • @sidreddy7030
    @sidreddy7030 Před 6 měsíci

    Neato! Needed you to come and save the day

  • @pritz9
    @pritz9 Před 6 měsíci

    neato !! bang explanation :-)) This is my 778th problem on LeetCode, solved many dp hards, but could not solve this, was clueless for a long time ! Thank You !

  • @triputrafauzanhradji8005
    @triputrafauzanhradji8005 Před 6 měsíci

    Neato!! I actually get lost since the DP Explanation segment but continued anyway because I was curious about the final solution, hoping I could gain some understanding after watching the whole thing.

  • @yaswanthkosuru
    @yaswanthkosuru Před 6 měsíci +2

    finally after spent hours i cant able to do
    after seing sliding window pattren + dp i came up with solution within seconds

  • @rohanthakur9159
    @rohanthakur9159 Před 6 měsíci

    Neato!!
    Just looking at a 10 pages long editorial gave me headache.
    Thanks for saving me.

  • @evanhuang756
    @evanhuang756 Před 6 měsíci

    Neato.
    I went with the DP solution at first .Sliding window optimization is great

  • @leemin-gyu3236
    @leemin-gyu3236 Před 6 měsíci

    Neato! Love the videos as well as the idea behind the different solutions :)

  • @ElliuHuang
    @ElliuHuang Před 6 měsíci

    neato! thanks for going through all the steps to solve the problem

  • @lPABLO_GAMING
    @lPABLO_GAMING Před 6 měsíci

    neato, going to have to rewatch this a few times to actually understand everything. interesting and tough problem, glad you made a video about it!

  • @aniketpatel8655
    @aniketpatel8655 Před 6 měsíci

    Neato! You explained things very easily. Great approach.
    Thank you for such solution

  • @saminhasan87
    @saminhasan87 Před 6 měsíci

    neato and neato again!! You have been superb. The way you solved the problem - from brute force to recursive dp to bottom-up dp to sliding window was just awesome. Thanks for the great effort.

  • @gitarowydominik
    @gitarowydominik Před 6 měsíci +2

    Neato. In Java the part "total -= prev[N - K]" won't work, as in some cases total can go negative. What is needed is "total = (total - prev[N - K] + MOD) % MOD;" or something similar, like adding MOD when total is negative.

    • @binh-nguyen-d
      @binh-nguyen-d Před 6 měsíci

      total includes prev[N-K] so why is the result when subtracting negative?

    • @gitarowydominik
      @gitarowydominik Před 6 měsíci

      @@binh-nguyen-dbecause of calculating the total % MOD and the underflow of int type.

    • @StephanieJohnston-rt7rq
      @StephanieJohnston-rt7rq Před 2 měsíci

      THANK YOU for this - I could not understand why one of my test cases was an extremely negative number

  • @ahasunos5914
    @ahasunos5914 Před 6 měsíci

    Neato!!
    The way you approach the solution step by step ❤️

  • @weronikalinda4917
    @weronikalinda4917 Před 6 měsíci +1

    Neato lol
    I always watch the whole thing because of your explanations and the path you show to actually get to the solution

  • @robertyamasaki1807
    @robertyamasaki1807 Před 6 měsíci

    neato, first time in a while just silencing everything and looking at the in depth solution

  • @ameetasom832
    @ameetasom832 Před 6 měsíci

    Neato!! loved the optimization part

  • @krishsharvesh8082
    @krishsharvesh8082 Před 6 měsíci +1

    Neato! I actually didn't grasp everything you just told, maybe i need to review dp again , anyways great teaching as always

  • @meylyssa3666
    @meylyssa3666 Před 6 měsíci

    Thank you for clear explanations!

  • @jacquelinejan5898
    @jacquelinejan5898 Před 6 měsíci

    Neato~Your videos have always helped me so much when practicing the problems!

  • @tkncompsci9353
    @tkncompsci9353 Před 6 měsíci

    Neato!! Excellent Explanation!! I like to watch your videos always whether I know the solution or not.

  • @ridamkrishna
    @ridamkrishna Před 6 měsíci

    neato! i watched this video that far because i liked the way we can progress from a better solution to the best solution.
    thanks neetcode

  • @shashwatkumar3079
    @shashwatkumar3079 Před 6 měsíci +1

    Always watch till the end because no matter how complicated, this guy can make it simpler only a little concentration is needed.

  • @diegobarbieri7804
    @diegobarbieri7804 Před 6 měsíci

    this video is amazing, really clever solution!

  • @bhavyagautam8036
    @bhavyagautam8036 Před 6 měsíci

    Neato! Loved your solution.

  • @tenthlegionstudios1343
    @tenthlegionstudios1343 Před 5 měsíci

    Made it to the end, spotted the optimization, but I failed to solve this on my first attempt. Also I have never seen an editorial with 7 solutions - this might be one of the longest editorials I have seen for a leetcode problem in terms of number of solutions. Great video! and clear explanation!

  • @jiteshpahwa266
    @jiteshpahwa266 Před 6 měsíci +2

    @NeetCodeIO you left a condition while subtracting from the total for C++ and Java users:
    if(total

    • @kartik6968
      @kartik6968 Před 6 měsíci

      Can you explain what does this do?
      I was getting the runtime error: signed integer overflow: -1533914095 + -675939082 cannot be represented in type 'int'

  • @rikthecuber
    @rikthecuber Před 6 měsíci

    Thanks for the soln Neato!

  • @jasonust3
    @jasonust3 Před 3 měsíci

    Genius solution with amazing explanation!

  • @sunilswizy8233
    @sunilswizy8233 Před 6 měsíci +1

    super explanation neato!!!

  • @hackytech7494
    @hackytech7494 Před 6 měsíci +1

    Neato! Well explained as always ❤

  • @sankalpchordia5245
    @sankalpchordia5245 Před 6 měsíci +7

    We need another algorithms super hard course in the platform!!

  • @varunpalsingh3822
    @varunpalsingh3822 Před 6 měsíci

    neato!! it was a tough problem, but learned a lot, thanks

  • @aswinnath8580
    @aswinnath8580 Před 6 měsíci

    neato! this is the hardest problem i've encountered in daily challenge.

  • @MP-ny3ep
    @MP-ny3ep Před 6 měsíci

    Amazing explanation !! Neato 😆😆

  • @arturremizov9296
    @arturremizov9296 Před 6 měsíci

    Neato
    Thank you for your videos!

  • @mohitkanodia5388
    @mohitkanodia5388 Před 6 měsíci

    Neato !! Great explanation

  • @insaeq
    @insaeq Před 6 měsíci

    great explanation!

  • @anirbansarkar4189
    @anirbansarkar4189 Před 6 měsíci

    superb explanation and approach

  • @VanjeAv
    @VanjeAv Před 5 měsíci

    Wow thank you so much neetio :)!

  • @AMakYu
    @AMakYu Před 6 měsíci

    Neato. Great explanation, but what a wild problem. I hope to never get asked to optimize a DP to this point....

  • @ajaykumargogineni3391
    @ajaykumargogineni3391 Před 6 měsíci

    neato!! Great explanation

  • @prateekgupta1417
    @prateekgupta1417 Před 6 měsíci

    Neato! Definitely a hard problem

  • @mire5234
    @mire5234 Před 6 měsíci

    This is ridiculously hard. I cannot imagine someone coming up with this solution during the interview.

  • @ngoquangtrung234
    @ngoquangtrung234 Před 6 měsíci

    Best explication.

  • @nooobody2751
    @nooobody2751 Před 6 měsíci

    neato ! you are the GOAT. Thanks a lot.

  • @blurryfca3
    @blurryfca3 Před 6 měsíci

    This came on yesterday's Daily question!, neatoo

  • @qboff4468
    @qboff4468 Před 6 měsíci

    Neato, you are the best, thank you😊

  • @michael._.
    @michael._. Před 6 měsíci

    ngl but this is one of the best questions in Leetcode and Neetcode has nailed it down with yet another legendary video (neato)

  • @Kaviarasu_NS
    @Kaviarasu_NS Před 6 měsíci

    neato!! big brain solutions ❤

  • @rileysikes9285
    @rileysikes9285 Před 6 měsíci

    neato!!!! Another great video

  • @user-zx8mh9cq7f
    @user-zx8mh9cq7f Před 6 měsíci

    neato! I am a beginner so it was very hard for me but still, I watched the full video and learned a lot.

  • @virgil246
    @virgil246 Před 6 měsíci

    neeto~ Thanks for the smooth explanation!

  • @sprajosh
    @sprajosh Před 6 měsíci

    Neato ~ This is a definitely a big brain problem.

  • @AbdulrahmanEgy
    @AbdulrahmanEgy Před 6 měsíci

    super neatooo!🔥

  • @tizekodnoon8305
    @tizekodnoon8305 Před 6 měsíci

    Neato! Head hurting right now 😨

  • @surajvalluru
    @surajvalluru Před 6 měsíci +1

    You can get recursive or bottom-up solution to get accepted by putting else break statement in for loop. We know that once k-i < 0 then for subsequent increments only consumes more time. Anyhow this is not optimised solution.

  • @yuxiangwang963
    @yuxiangwang963 Před 5 měsíci

    Neato, really a HARD one!

  • @VasudevaK
    @VasudevaK Před 6 měsíci +1

    Perfect tutorial🤍

  • @timlu4734
    @timlu4734 Před 4 dny

    neato! Really helpful video, as always. Save me a lot of time, thanks.

  • @macwett
    @macwett Před 6 měsíci

    neato! this was really an interesting problem

  • @EduarteBDO
    @EduarteBDO Před 6 měsíci

    neato. As someone who couldn't figure even the dfs solution but watched everything this is super challenging probably impossible at my current level. I gess that I need to draw more and pratice more

  • @Cheng-K
    @Cheng-K Před 6 měsíci +1

    Neato! 🧠

  • @ankurbose7672
    @ankurbose7672 Před 6 měsíci

    Neato!!! How long did it take for you to get to the optimal solution on your own? Just curious.

  • @sandrobatistasantos514
    @sandrobatistasantos514 Před 6 měsíci

    Neato! ❤

  • @byduhlusional
    @byduhlusional Před 6 měsíci

    Neato. It's crazy how much optimization you have to do for this one, but I guess that's why it's a hard problem lol

  • @krateskim4169
    @krateskim4169 Před 6 měsíci

    Hey neato it was a great video with an awesome explanation

  • @yashraj3005
    @yashraj3005 Před 6 měsíci +1

    We love you neetcode

  • @nishantketu2040
    @nishantketu2040 Před 6 měsíci +1

    neato👍👍

  • @ankitkumaryadav562
    @ankitkumaryadav562 Před měsícem

    Thanks BRO

  • @nikhil199029
    @nikhil199029 Před 3 měsíci

    at 12:28, why are donig res = res+ (count(n-1,k-1))?

  • @alexandruolaru7855
    @alexandruolaru7855 Před 6 měsíci

    Neato 🎉

  • @hikmetdemir1032
    @hikmetdemir1032 Před 6 měsíci

    Could you please make an example training video for backtracking, graphs, tree and sliding window, starting from easy level to difficult level, just like you do for dynamic programming they are very instructive

  • @estifanosbireda1892
    @estifanosbireda1892 Před 6 měsíci

    Great explanation for a Hard problem, I found it hard to get the recurrence relation even after I knew it's a dp problem. How did you get the intuition for using the relative ordering?

  • @singletmat5172
    @singletmat5172 Před 6 měsíci

    Neato!

  • @o_tega627
    @o_tega627 Před 6 měsíci

    Neato!!

  • @AndriiRiabchuk
    @AndriiRiabchuk Před 6 měsíci

    neato; Thanks!

  • @inzamamulhaque2153
    @inzamamulhaque2153 Před 6 měsíci

    neato 🎉

  • @aswathchandrasekar2917
    @aswathchandrasekar2917 Před 6 měsíci

    Neato. Nice explanation. But have to come back to it later ;(

  • @phuongnguyenhuynhanh7462
    @phuongnguyenhuynhanh7462 Před 6 měsíci

    damn, i solved daily problems everyday and your video is always the highlight of my day

  • @harshithdesai9989
    @harshithdesai9989 Před 6 měsíci

    neato!!

  • @praveenj3112
    @praveenj3112 Před 6 měsíci

    Neato !!!