K Inverse Pairs Array - Leetcode 629 - Python

  Рет қаралды 15,440

NeetCodeIO

NeetCodeIO

Күн бұрын

🚀 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

Пікірлер: 337
@FirmamentTSW
@FirmamentTSW 5 ай бұрын
neato!! learned a lot from how you gradually get the final solution.
@satyamjha68
@satyamjha68 5 ай бұрын
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!!
@anthonyleong4238
@anthonyleong4238 5 ай бұрын
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.
@wintersol9921
@wintersol9921 5 ай бұрын
I don't know how you do it, put you always explain just the best and the simplest way possible. KZbin 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 5 ай бұрын
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 5 ай бұрын
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
@jonathanlo1026 5 ай бұрын
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
@walkastray007 5 ай бұрын
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
@yaswanthkosuru
@yaswanthkosuru 5 ай бұрын
finally after spent hours i cant able to do after seing sliding window pattren + dp i came up with solution within seconds
@user-ue7xt5hv9i
@user-ue7xt5hv9i 5 ай бұрын
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 5 ай бұрын
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.
@abhishekkaintura6398
@abhishekkaintura6398 5 ай бұрын
the way you explain the problem is really appreciable
@gitarowydominik
@gitarowydominik 5 ай бұрын
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 Ай бұрын
THANK YOU for this - I could not understand why one of my test cases was an extremely negative number
@SanketBhat7
@SanketBhat7 5 ай бұрын
Neato!! As far as knowledge is gained and content is understandable, doesn't matter how long the video is .. Thanks for the video
@shashwatkumar3079
@shashwatkumar3079 5 ай бұрын
Always watch till the end because no matter how complicated, this guy can make it simpler only a little concentration is needed.
@rahulsbhatt
@rahulsbhatt 5 ай бұрын
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!
@pritz9
@pritz9 5 ай бұрын
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 !
@sachinsinghbhadoriya9523
@sachinsinghbhadoriya9523 5 ай бұрын
Neato! This was one of THE problems I was not able to get my head around! Thanks for all the good work!
@evanhuang756
@evanhuang756 5 ай бұрын
Neato. I went with the DP solution at first .Sliding window optimization is great
@hamirmahal
@hamirmahal 5 ай бұрын
Neat-o! I appreciate the longer length videos. I think they're very helpful. Thank you for making them.
@aryanikale7187
@aryanikale7187 5 ай бұрын
Thank you for this, definitely a hard problem
@radon3894
@radon3894 5 ай бұрын
Another excellent video, appreciate the time to explain your thought process!
@robertyamasaki1807
@robertyamasaki1807 5 ай бұрын
neato, first time in a while just silencing everything and looking at the in depth solution
@rohanthakur9159
@rohanthakur9159 5 ай бұрын
Neato!! Just looking at a 10 pages long editorial gave me headache. Thanks for saving me.
@triputrafauzanhradji8005
@triputrafauzanhradji8005 5 ай бұрын
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.
@saminhasan87
@saminhasan87 5 ай бұрын
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.
@sankalpchordia5245
@sankalpchordia5245 5 ай бұрын
We need another algorithms super hard course in the platform!!
@weronikalinda4917
@weronikalinda4917 5 ай бұрын
Neato lol I always watch the whole thing because of your explanations and the path you show to actually get to the solution
@aniketpatel8655
@aniketpatel8655 5 ай бұрын
Neato! You explained things very easily. Great approach. Thank you for such solution
@meylyssa3666
@meylyssa3666 5 ай бұрын
Thank you for clear explanations!
@ameetasom832
@ameetasom832 5 ай бұрын
Neato!! loved the optimization part
@mire5234
@mire5234 5 ай бұрын
This is ridiculously hard. I cannot imagine someone coming up with this solution during the interview.
@jiteshpahwa266
@jiteshpahwa266 5 ай бұрын
@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'
@ahasunos5914
@ahasunos5914 5 ай бұрын
Neato!! The way you approach the solution step by step ❤️
@tenthlegionstudios1343
@tenthlegionstudios1343 5 ай бұрын
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!
@jasonust3
@jasonust3 2 ай бұрын
Genius solution with amazing explanation!
@piyushgupta7210
@piyushgupta7210 5 ай бұрын
neato! thanks man.. you really are making stuff easier for beginners
@surajvalluru
@surajvalluru 5 ай бұрын
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.
@lPABLO_GAMING
@lPABLO_GAMING 5 ай бұрын
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!
@tkncompsci9353
@tkncompsci9353 5 ай бұрын
Neato!! Excellent Explanation!! I like to watch your videos always whether I know the solution or not.
@sidreddy7030
@sidreddy7030 5 ай бұрын
Neato! Needed you to come and save the day
@krishsharvesh8082
@krishsharvesh8082 5 ай бұрын
Neato! I actually didn't grasp everything you just told, maybe i need to review dp again , anyways great teaching as always
@diegobarbieri7804
@diegobarbieri7804 5 ай бұрын
this video is amazing, really clever solution!
@lawlesslotus
@lawlesslotus 5 ай бұрын
neato! thanks for the explanation, I always jump to your channel whenever there's a Hard problem.
@ridamkrishna
@ridamkrishna 5 ай бұрын
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
@ElliuHuang
@ElliuHuang 5 ай бұрын
neato! thanks for going through all the steps to solve the problem
@ngoquangtrung234
@ngoquangtrung234 5 ай бұрын
Best explication.
@hackytech7494
@hackytech7494 5 ай бұрын
Neato! Well explained as always ❤
@jacquelinejan5898
@jacquelinejan5898 5 ай бұрын
Neato~Your videos have always helped me so much when practicing the problems!
@anirbansarkar4189
@anirbansarkar4189 5 ай бұрын
superb explanation and approach
@bhavyagautam8036
@bhavyagautam8036 5 ай бұрын
Neato! Loved your solution.
@sunilswizy8233
@sunilswizy8233 5 ай бұрын
super explanation neato!!!
@yashraj3005
@yashraj3005 5 ай бұрын
We love you neetcode
@prateekgupta1417
@prateekgupta1417 5 ай бұрын
Neato! Definitely a hard problem
@mohitkanodia5388
@mohitkanodia5388 5 ай бұрын
Neato !! Great explanation
@aswinnath8580
@aswinnath8580 5 ай бұрын
neato! this is the hardest problem i've encountered in daily challenge.
@arturremizov9296
@arturremizov9296 5 ай бұрын
Neato Thank you for your videos!
@leemin-gyu3236
@leemin-gyu3236 5 ай бұрын
Neato! Love the videos as well as the idea behind the different solutions :)
@qboff4468
@qboff4468 5 ай бұрын
Neato, you are the best, thank you😊
@rikthecuber
@rikthecuber 5 ай бұрын
Thanks for the soln Neato!
@blurryfca3
@blurryfca3 5 ай бұрын
This came on yesterday's Daily question!, neatoo
@MP-ny3ep
@MP-ny3ep 5 ай бұрын
Amazing explanation !! Neato 😆😆
@VasudevaK
@VasudevaK 5 ай бұрын
Perfect tutorial🤍
@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)
@sprajosh
@sprajosh 5 ай бұрын
Neato ~ This is a definitely a big brain problem.
@AMakYu
@AMakYu 5 ай бұрын
Neato. Great explanation, but what a wild problem. I hope to never get asked to optimize a DP to this point....
@VanjeAv
@VanjeAv 4 ай бұрын
Wow thank you so much neetio :)!
@EduarteBDO
@EduarteBDO 5 ай бұрын
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
@insaeq
@insaeq 5 ай бұрын
great explanation!
@tizekodnoon8305
@tizekodnoon8305 5 ай бұрын
Neato! Head hurting right now 😨
@ajaykumargogineni3391
@ajaykumargogineni3391 5 ай бұрын
neato!! Great explanation
@varunpalsingh3822
@varunpalsingh3822 5 ай бұрын
neato!! it was a tough problem, but learned a lot, thanks
@virgil246
@virgil246 5 ай бұрын
neeto~ Thanks for the smooth explanation!
@user-zx8mh9cq7f
@user-zx8mh9cq7f 5 ай бұрын
neato! I am a beginner so it was very hard for me but still, I watched the full video and learned a lot.
@AbdulrahmanEgy
@AbdulrahmanEgy 5 ай бұрын
super neatooo!🔥
@nooobody2751
@nooobody2751 5 ай бұрын
neato ! you are the GOAT. Thanks a lot.
@rileysikes9285
@rileysikes9285 5 ай бұрын
neato!!!! Another great video
@yuxiangwang963
@yuxiangwang963 5 ай бұрын
Neato, really a HARD one!
@Kaviarasu_NS
@Kaviarasu_NS 5 ай бұрын
neato!! big brain solutions ❤
@byduhlusional
@byduhlusional 5 ай бұрын
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
@ankitkumaryadav562
@ankitkumaryadav562 13 күн бұрын
Thanks BRO
@phuongnguyenhuynhanh7462
@phuongnguyenhuynhanh7462 5 ай бұрын
damn, i solved daily problems everyday and your video is always the highlight of my day
@macwett
@macwett 5 ай бұрын
neato! this was really an interesting problem
@Cheng-K
@Cheng-K 5 ай бұрын
Neato! 🧠
@krateskim4169
@krateskim4169 5 ай бұрын
Hey neato it was a great video with an awesome explanation
@art4eigen93
@art4eigen93 5 ай бұрын
neato! but repeating the whole again, and again.
@hikmetdemir1032
@hikmetdemir1032 5 ай бұрын
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
@sandrobatistasantos514
@sandrobatistasantos514 5 ай бұрын
Neato! ❤
@AndriiRiabchuk
@AndriiRiabchuk 5 ай бұрын
neato; Thanks!
@swanv951
@swanv951 5 ай бұрын
In the recursive solution, you only need to take i up to k and not up to n, since we know that (k-i) being negative is going to return 0 from recursive call. That makes it O(n*k*k) instead of O(n*n*k). It is still very bad bad but doesn't give TLE (at least in Java)
@nishantketu2040
@nishantketu2040 5 ай бұрын
neato👍👍
@alexandruolaru7855
@alexandruolaru7855 5 ай бұрын
Neato 🎉
@walkastray007
@walkastray007 5 ай бұрын
Neeto. I didn't make it to the solution, but I did think about the brute force one.
@aswathchandrasekar2917
@aswathchandrasekar2917 5 ай бұрын
Neato. Nice explanation. But have to come back to it later ;(
@nicdemai
@nicdemai 5 ай бұрын
neato all the way through
@lucidgames2580
@lucidgames2580 5 ай бұрын
certified neato!!
@inzamamulhaque2153
@inzamamulhaque2153 5 ай бұрын
neato 🎉
@aniruddhachaki7165
@aniruddhachaki7165 5 ай бұрын
neato! it's 12:48 am here!
@o_tega627
@o_tega627 5 ай бұрын
Neato!!
@slimshady2381
@slimshady2381 5 ай бұрын
Neato!.
Partition Array for Maximum Sum - Leetcode 1043 - Python
27:33
NeetCodeIO
Рет қаралды 16 М.
孩子多的烦恼?#火影忍者 #家庭 #佐助
00:31
火影忍者一家
Рет қаралды 47 МЛН
Heartwarming: Stranger Saves Puppy from Hot Car #shorts
00:22
Fabiosa Best Lifehacks
Рет қаралды 20 МЛН
Greatest Common Divisor Traversal - Leetcode 2709 - Python
24:30
Dota2 Senate - Leetcode 649 - Python
14:48
NeetCodeIO
Рет қаралды 18 М.
LeetCode - 54. Spiral Matrix  | Array |  Python | Java
8:38
Orkhan Gasanov
Рет қаралды 53
Largest Divisible Subset - Leetcode 368 - Python
22:57
NeetCodeIO
Рет қаралды 14 М.
Maximum Sum Circular Subarray - Leetcode 918 - Python
16:49
NeetCodeIO
Рет қаралды 28 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 310 М.
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,2 МЛН
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 614 М.
Out of Boundary Paths - Leetcode 576 - Python
18:20
NeetCodeIO
Рет қаралды 15 М.
Bitwise AND of Numbers Range - Leetcode 201 - Python
18:25
NeetCodeIO
Рет қаралды 12 М.