Тёмный

K Inverse Pairs Array - Leetcode 629 - Python 

Подписаться
Просмотров 17 тыс.
% 649

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🧑‍💼 LinkedIn: www.linkedin.com/in/navdeep-singh-3aaa14161/
🐦 Twitter: neetcode1
⭐ BLIND-75 PLAYLIST: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-KLlXCFG5TnA.html
Problem Link: leetcode.com/problems/k-inverse-pairs-array/
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

Опубликовано:

 

27 янв 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 347   
@FirmamentTSW
@FirmamentTSW 8 месяцев назад
neato!! learned a lot from how you gradually get the final solution.
@wintersol9921
@wintersol9921 8 месяцев назад
I don't know how you do it, put you always explain just the best and the simplest way possible. RU-vid 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
@simonvutov7575
@simonvutov7575 8 месяцев назад
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 8 месяцев назад
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!
@BlunderArmour
@BlunderArmour 8 месяцев назад
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.
@walkastray007
@walkastray007 8 месяцев назад
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
@satyamjha68
@satyamjha68 8 месяцев назад
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!!
@surajvalluru
@surajvalluru 8 месяцев назад
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.
@shashwatkumar3079
@shashwatkumar3079 8 месяцев назад
Always watch till the end because no matter how complicated, this guy can make it simpler only a little concentration is needed.
@anthonyleong4238
@anthonyleong4238 8 месяцев назад
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.
@EvanKendrick-d8h
@EvanKendrick-d8h 8 месяцев назад
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.
@rahulsbhatt
@rahulsbhatt 8 месяцев назад
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!
@SanketBhat7
@SanketBhat7 8 месяцев назад
Neato!! As far as knowledge is gained and content is understandable, doesn't matter how long the video is .. Thanks for the video
@yaswanthkosuru
@yaswanthkosuru 8 месяцев назад
finally after spent hours i cant able to do after seing sliding window pattren + dp i came up with solution within seconds
@sachinsinghbhadoriya9523
@sachinsinghbhadoriya9523 8 месяцев назад
Neato! This was one of THE problems I was not able to get my head around! Thanks for all the good work!
@sankalpchordia5245
@sankalpchordia5245 8 месяцев назад
We need another algorithms super hard course in the platform!!
@tenthlegionstudios1343
@tenthlegionstudios1343 8 месяцев назад
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!
@LakshyaSethi-g7w
@LakshyaSethi-g7w 8 месяцев назад
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!
@hamirmahal
@hamirmahal 8 месяцев назад
Neat-o! I appreciate the longer length videos. I think they're very helpful. Thank you for making them.
@gitarowydominik
@gitarowydominik 8 месяцев назад
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 8 месяцев назад
total includes prev[N-K] so why is the result when subtracting negative?
@gitarowydominik
@gitarowydominik 8 месяцев назад
@@binh-nguyen-dbecause of calculating the total % MOD and the underflow of int type.
@StephanieJohnston-rt7rq
@StephanieJohnston-rt7rq 5 месяцев назад
THANK YOU for this - I could not understand why one of my test cases was an extremely negative number
@krishsharvesh8082
@krishsharvesh8082 8 месяцев назад
Neato! I actually didn't grasp everything you just told, maybe i need to review dp again , anyways great teaching as always
@radon3894
@radon3894 8 месяцев назад
Another excellent video, appreciate the time to explain your thought process!
@pritz9
@pritz9 8 месяцев назад
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 !
@abhishekkaintura6398
@abhishekkaintura6398 8 месяцев назад
the way you explain the problem is really appreciable
@tkncompsci9353
@tkncompsci9353 8 месяцев назад
Neato!! Excellent Explanation!! I like to watch your videos always whether I know the solution or not.
@robertyamasaki1807
@robertyamasaki1807 8 месяцев назад
neato, first time in a while just silencing everything and looking at the in depth solution
@aniketpatel8655
@aniketpatel8655 8 месяцев назад
Neato! You explained things very easily. Great approach. Thank you for such solution
@estifanosbireda1892
@estifanosbireda1892 8 месяцев назад
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?
@jiteshpahwa266
@jiteshpahwa266 8 месяцев назад
@NeetCodeIO you left a condition while subtracting from the total for C++ and Java users: if(total
@kartik6968
@kartik6968 8 месяцев назад
Can you explain what does this do? I was getting the runtime error: signed integer overflow: -1533914095 + -675939082 cannot be represented in type 'int'
@weronikalinda4917
@weronikalinda4917 8 месяцев назад
Neato lol I always watch the whole thing because of your explanations and the path you show to actually get to the solution
@mire5234
@mire5234 8 месяцев назад
This is ridiculously hard. I cannot imagine someone coming up with this solution during the interview.
@saminhasan87
@saminhasan87 8 месяцев назад
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.
@jasonust3
@jasonust3 5 месяцев назад
Genius solution with amazing explanation!
@ankurbose7672
@ankurbose7672 8 месяцев назад
Neato!!! How long did it take for you to get to the optimal solution on your own? Just curious.
@rohanthakur9159
@rohanthakur9159 8 месяцев назад
Neato!! Just looking at a 10 pages long editorial gave me headache. Thanks for saving me.
@hackytech7494
@hackytech7494 8 месяцев назад
Neato! Well explained as always ❤
@evanhuang756
@evanhuang756 8 месяцев назад
Neato. I went with the DP solution at first .Sliding window optimization is great
@PabloElBlanco
@PabloElBlanco 8 месяцев назад
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!
@triputrafauzanhradji8005
@triputrafauzanhradji8005 8 месяцев назад
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.
@ahasunos5914
@ahasunos5914 8 месяцев назад
Neato!! The way you approach the solution step by step ❤️
@विक्रमचौहान-द2थ
@विक्रमचौहान-द2थ 8 месяцев назад
neato! I am a beginner so it was very hard for me but still, I watched the full video and learned a lot.
@diegobarbieri7804
@diegobarbieri7804 8 месяцев назад
this video is amazing, really clever solution!
@yashraj3005
@yashraj3005 8 месяцев назад
We love you neetcode
@EduarteBDO
@EduarteBDO 8 месяцев назад
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
@michael._.
@michael._. 8 месяцев назад
ngl but this is one of the best questions in Leetcode and Neetcode has nailed it down with yet another legendary video (neato)
@lawlesslotus
@lawlesslotus 8 месяцев назад
neato! thanks for the explanation, I always jump to your channel whenever there's a Hard problem.
@meylyssa3666
@meylyssa3666 8 месяцев назад
Thank you for clear explanations!
@ridamkrishna
@ridamkrishna 8 месяцев назад
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
@timlu4734
@timlu4734 2 месяца назад
neato! Really helpful video, as always. Save me a lot of time, thanks.
@varunpalsingh3822
@varunpalsingh3822 8 месяцев назад
neato!! it was a tough problem, but learned a lot, thanks
@ElliuHuang
@ElliuHuang 8 месяцев назад
neato! thanks for going through all the steps to solve the problem
@AMakYu
@AMakYu 8 месяцев назад
Neato. Great explanation, but what a wild problem. I hope to never get asked to optimize a DP to this point....
@jacquelinejan5898
@jacquelinejan5898 8 месяцев назад
Neato~Your videos have always helped me so much when practicing the problems!
@divyamdubey9333
@divyamdubey9333 8 месяцев назад
Neato, Still finding a bit hard to not look up solutions straight away and give it a go by myself. Although I get the approach immediately as you start to explain, but I wanna know how to develop the mindset to not look the solution and try for a good 30-40 mins? Lemme know!
@leemin-gyu3236
@leemin-gyu3236 8 месяцев назад
Neato! Love the videos as well as the idea behind the different solutions :)
@piyushgupta7210
@piyushgupta7210 8 месяцев назад
neato! thanks man.. you really are making stuff easier for beginners
@johnj171
@johnj171 2 месяца назад
Hey GodFather I love you video like every videos!! I have a doubt that at time 4:55 when we put 1 at the 0th index then we can have one inverse pair because 1,3,2 is something we can form then we have formed one index pair right? just a doubt But i understand the overall logic of the solution. Love you and your content GodFather Love you Neetcode!
@hikmetdemir1032
@hikmetdemir1032 8 месяцев назад
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
@squid84202
@squid84202 8 месяцев назад
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
@aryanikale7187
@aryanikale7187 8 месяцев назад
Thank you for this, definitely a hard problem
@blurryfca3
@blurryfca3 8 месяцев назад
This came on yesterday's Daily question!, neatoo
@sidreddy7030
@sidreddy7030 8 месяцев назад
Neato! Needed you to come and save the day
@existanz
@existanz 8 месяцев назад
Hi, Neato. Is there a bug here? Such a case is possible when we subtract a number that we didn't take by MOD (on 12 line) and add with MOD (on 13). I think we need to move '% MOD' to 14 line.
@kartik6968
@kartik6968 8 месяцев назад
I was working in cpp and got this error: runtime error: signed integer overflow: -1533914095 + -675939082 cannot be represented in type 'int'
@anirbansarkar4189
@anirbansarkar4189 8 месяцев назад
superb explanation and approach
@ameetasom832
@ameetasom832 8 месяцев назад
Neato!! loved the optimization part
@ashutoshsamantaray6596
@ashutoshsamantaray6596 8 месяцев назад
neato, if you had to prepare one topic from your tree, before interview day, what will you choose??
@aswinnath8580
@aswinnath8580 8 месяцев назад
neato! this is the hardest problem i've encountered in daily challenge.
@phuongnguyenhuynhanh7462
@phuongnguyenhuynhanh7462 8 месяцев назад
damn, i solved daily problems everyday and your video is always the highlight of my day
@ronbuchanan5432
@ronbuchanan5432 8 месяцев назад
Kudos to Neato! (don't you have video statistics though? haha)
@sprajosh
@sprajosh 8 месяцев назад
Neato ~ This is a definitely a big brain problem.
@walkastray007
@walkastray007 8 месяцев назад
Neeto. I didn't make it to the solution, but I did think about the brute force one.
@ngoquangtrung234
@ngoquangtrung234 8 месяцев назад
Best explication.
@virgil246
@virgil246 8 месяцев назад
neeto~ Thanks for the smooth explanation!
@mohitkanodia5388
@mohitkanodia5388 8 месяцев назад
Neato !! Great explanation
@johnj171
@johnj171 2 месяца назад
God Father !!! I have made the video so farr you are amazing the king GODFATHER!!! love you content
@qboff4468
@qboff4468 8 месяцев назад
Neato, you are the best, thank you😊
@swanv951
@swanv951 8 месяцев назад
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)
@krateskim4169
@krateskim4169 8 месяцев назад
Hey neato it was a great video with an awesome explanation
@tizekodnoon8305
@tizekodnoon8305 8 месяцев назад
Neato! Head hurting right now 😨
@arturremizov9296
@arturremizov9296 8 месяцев назад
Neato Thank you for your videos!
@aswathchandrasekar2917
@aswathchandrasekar2917 8 месяцев назад
Neato. Nice explanation. But have to come back to it later ;(
@nishantketu2040
@nishantketu2040 8 месяцев назад
neato👍👍
@sunilswizy8233
@sunilswizy8233 8 месяцев назад
super explanation neato!!!
@VanjeAv
@VanjeAv 7 месяцев назад
Wow thank you so much neetio :)!
@rileysikes9285
@rileysikes9285 8 месяцев назад
neato!!!! Another great video
@ajaykumargogineni3391
@ajaykumargogineni3391 8 месяцев назад
neato!! Great explanation
@art4eigen93
@art4eigen93 8 месяцев назад
neato! but repeating the whole again, and again.
@VasudevaK
@VasudevaK 8 месяцев назад
Perfect tutorial🤍
@Cheng-K
@Cheng-K 8 месяцев назад
Neato! 🧠
@prateekgupta1417
@prateekgupta1417 8 месяцев назад
Neato! Definitely a hard problem
@bhavyagautam8036
@bhavyagautam8036 8 месяцев назад
Neato! Loved your solution.
@rikthecuber
@rikthecuber 8 месяцев назад
Thanks for the soln Neato!
@nooobody2751
@nooobody2751 8 месяцев назад
neato ! you are the GOAT. Thanks a lot.
@muqto8867
@muqto8867 8 месяцев назад
Hey can you do this easy problem next: 459. Repeated Substring Pattern
@insaeq
@insaeq 8 месяцев назад
great explanation!
@shaco6630
@shaco6630 8 месяцев назад
The recursive solution did not get accepted, but the DP and space optimized DP did get accepted (In Kotlin)
@MP-ny3ep
@MP-ny3ep 8 месяцев назад
Amazing explanation !! Neato 😆😆
@erminiottone
@erminiottone 8 месяцев назад
I passed the OJ with the first recursive solution in C++ with TC O(n*k^2) 😅
@MrKB_SSJ2
@MrKB_SSJ2 8 месяцев назад
25:40 DAMNNNNN NOTICED THE OPTIMIZATION. IMAGINE SOMEONE ASKS THIS IN THE INTERVIEW MANNN
@aniruddhachaki7165
@aniruddhachaki7165 8 месяцев назад
neato! it's 12:48 am here!