K Inverse Pairs Array - Leetcode 629 - Python

🚀 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

Пікірлер: 341

  • @FirmamentTSW
    @FirmamentTSW5 ай бұрын

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

  • @wintersol9921
    @wintersol99215 ай бұрын

    I don't know how you do it, put you always explain just the best and the simplest way possible. KZread 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
    @BlunderArmour5 ай бұрын

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

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

  • @jonathanlo1026
    @jonathanlo10265 ай бұрын

    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!

  • @walkastray007
    @walkastray0075 ай бұрын

    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

  • @user-ue7xt5hv9i
    @user-ue7xt5hv9i5 ай бұрын

    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-ks7dw5uc6w5 ай бұрын

    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.

  • @satyamjha68
    @satyamjha685 ай бұрын

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

  • @sachinsinghbhadoriya9523
    @sachinsinghbhadoriya95235 ай бұрын

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

  • @yaswanthkosuru
    @yaswanthkosuru5 ай бұрын

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

  • @SanketBhat7
    @SanketBhat75 ай бұрын

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

  • @rahulsbhatt
    @rahulsbhatt5 ай бұрын

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

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

  • @radon3894
    @radon38945 ай бұрын

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

  • @abhishekkaintura6398
    @abhishekkaintura63985 ай бұрын

    the way you explain the problem is really appreciable

  • @pritz9
    @pritz95 ай бұрын

    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 !

  • @anthonyleong4238
    @anthonyleong42385 ай бұрын

    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.

  • @lawlesslotus
    @lawlesslotus5 ай бұрын

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

  • @piyushgupta7210
    @piyushgupta72105 ай бұрын

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

  • @evanhuang756
    @evanhuang7565 ай бұрын

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

  • @sidreddy7030
    @sidreddy70305 ай бұрын

    Neato! Needed you to come and save the day

  • @lPABLO_GAMING
    @lPABLO_GAMING5 ай бұрын

    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!

  • @rohanthakur9159
    @rohanthakur91595 ай бұрын

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

  • @aryanikale7187
    @aryanikale71875 ай бұрын

    Thank you for this, definitely a hard problem

  • @triputrafauzanhradji8005
    @triputrafauzanhradji80055 ай бұрын

    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.

  • @shashwatkumar3079
    @shashwatkumar30795 ай бұрын

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

  • @ElliuHuang
    @ElliuHuang5 ай бұрын

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

  • @ahasunos5914
    @ahasunos59145 ай бұрын

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

  • @leemin-gyu3236
    @leemin-gyu32365 ай бұрын

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

  • @aniketpatel8655
    @aniketpatel86555 ай бұрын

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

  • @robertyamasaki1807
    @robertyamasaki18075 ай бұрын

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

  • @weronikalinda4917
    @weronikalinda49175 ай бұрын

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

  • @saminhasan87
    @saminhasan875 ай бұрын

    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.

  • @krishsharvesh8082
    @krishsharvesh80825 ай бұрын

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

  • @ameetasom832
    @ameetasom8325 ай бұрын

    Neato!! loved the optimization part

  • @jacquelinejan5898
    @jacquelinejan58985 ай бұрын

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

  • @ridamkrishna
    @ridamkrishna5 ай бұрын

    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

  • @meylyssa3666
    @meylyssa36665 ай бұрын

    Thank you for clear explanations!

  • @tkncompsci9353
    @tkncompsci93535 ай бұрын

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

  • @diegobarbieri7804
    @diegobarbieri78045 ай бұрын

    this video is amazing, really clever solution!

  • @jasonust3
    @jasonust33 ай бұрын

    Genius solution with amazing explanation!

  • @hackytech7494
    @hackytech74945 ай бұрын

    Neato! Well explained as always ❤

  • @aswinnath8580
    @aswinnath85805 ай бұрын

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

  • @varunpalsingh3822
    @varunpalsingh38225 ай бұрын

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

  • @tenthlegionstudios1343
    @tenthlegionstudios13435 ай бұрын

    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!

  • @bhavyagautam8036
    @bhavyagautam80365 ай бұрын

    Neato! Loved your solution.

  • @gitarowydominik
    @gitarowydominik5 ай бұрын

    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

    5 ай бұрын

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

  • @gitarowydominik

    @gitarowydominik

    5 ай бұрын

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

  • @StephanieJohnston-rt7rq

    @StephanieJohnston-rt7rq

    2 ай бұрын

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

  • @VanjeAv
    @VanjeAv4 ай бұрын

    Wow thank you so much neetio :)!

  • @mire5234
    @mire52345 ай бұрын

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

  • @sankalpchordia5245
    @sankalpchordia52455 ай бұрын

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

  • @arturremizov9296
    @arturremizov92965 ай бұрын

    Neato Thank you for your videos!

  • @AMakYu
    @AMakYu5 ай бұрын

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

  • @rikthecuber
    @rikthecuber5 ай бұрын

    Thanks for the soln Neato!

  • @mohitkanodia5388
    @mohitkanodia53885 ай бұрын

    Neato !! Great explanation

  • @anirbansarkar4189
    @anirbansarkar41895 ай бұрын

    superb explanation and approach

  • @michael._.
    @michael._.5 ай бұрын

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

  • @sunilswizy8233
    @sunilswizy82335 ай бұрын

    super explanation neato!!!

  • @sprajosh
    @sprajosh5 ай бұрын

    Neato ~ This is a definitely a big brain problem.

  • @virgil246
    @virgil2465 ай бұрын

    neeto~ Thanks for the smooth explanation!

  • @MP-ny3ep
    @MP-ny3ep5 ай бұрын

    Amazing explanation !! Neato 😆😆

  • @prateekgupta1417
    @prateekgupta14175 ай бұрын

    Neato! Definitely a hard problem

  • @qboff4468
    @qboff44685 ай бұрын

    Neato, you are the best, thank you😊

  • @ajaykumargogineni3391
    @ajaykumargogineni33915 ай бұрын

    neato!! Great explanation

  • @nooobody2751
    @nooobody27515 ай бұрын

    neato ! you are the GOAT. Thanks a lot.

  • @rileysikes9285
    @rileysikes92855 ай бұрын

    neato!!!! Another great video

  • @ngoquangtrung234
    @ngoquangtrung2345 ай бұрын

    Best explication.

  • @blurryfca3
    @blurryfca35 ай бұрын

    This came on yesterday's Daily question!, neatoo

  • @tizekodnoon8305
    @tizekodnoon83055 ай бұрын

    Neato! Head hurting right now 😨

  • @jiteshpahwa266
    @jiteshpahwa2665 ай бұрын

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

  • @kartik6968

    @kartik6968

    5 ай бұрын

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

  • @insaeq
    @insaeq5 ай бұрын

    great explanation!

  • @yuxiangwang963
    @yuxiangwang9635 ай бұрын

    Neato, really a HARD one!

  • @user-zx8mh9cq7f
    @user-zx8mh9cq7f5 ай бұрын

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

  • @Kaviarasu_NS
    @Kaviarasu_NS5 ай бұрын

    neato!! big brain solutions ❤

  • @AbdulrahmanEgy
    @AbdulrahmanEgy5 ай бұрын

    super neatooo!🔥

  • @macwett
    @macwett5 ай бұрын

    neato! this was really an interesting problem

  • @yashraj3005
    @yashraj30055 ай бұрын

    We love you neetcode

  • @VasudevaK
    @VasudevaK5 ай бұрын

    Perfect tutorial🤍

  • @krateskim4169
    @krateskim41695 ай бұрын

    Hey neato it was a great video with an awesome explanation

  • @EduarteBDO
    @EduarteBDO5 ай бұрын

    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-K5 ай бұрын

    Neato! 🧠

  • @byduhlusional
    @byduhlusional5 ай бұрын

    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

  • @phuongnguyenhuynhanh7462
    @phuongnguyenhuynhanh74625 ай бұрын

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

  • @sandrobatistasantos514
    @sandrobatistasantos5145 ай бұрын

    Neato! ❤

  • @AndriiRiabchuk
    @AndriiRiabchuk5 ай бұрын

    neato; Thanks!

  • @ankitkumaryadav562
    @ankitkumaryadav56228 күн бұрын

    Thanks BRO

  • @aswathchandrasekar2917
    @aswathchandrasekar29175 ай бұрын

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

  • @inzamamulhaque2153
    @inzamamulhaque21535 ай бұрын

    neato 🎉

  • @nishantketu2040
    @nishantketu20405 ай бұрын

    neato👍👍

  • @singletmat5172
    @singletmat51725 ай бұрын

    Neato!

  • @surajvalluru
    @surajvalluru5 ай бұрын

    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.

  • @lucidgames2580
    @lucidgames25805 ай бұрын

    certified neato!!

  • @art4eigen93
    @art4eigen935 ай бұрын

    neato! but repeating the whole again, and again.

  • @harshithdesai9989
    @harshithdesai99895 ай бұрын

    neato!!

  • @alexandruolaru7855
    @alexandruolaru78555 ай бұрын

    Neato 🎉

  • @o_tega627
    @o_tega6275 ай бұрын

    Neato!!

  • @ankurbose7672
    @ankurbose76725 ай бұрын

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

  • @Kugelblitz2b
    @Kugelblitz2b3 ай бұрын

    neato 😭🤓

  • @okcodingbeast
    @okcodingbeast5 ай бұрын

    neato!

  • @praveenj3112
    @praveenj31125 ай бұрын

    Neato !!!