K Inverse Pairs Array - Leetcode 629 - Python

  Рет қаралды 17,083

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 349
@FirmamentTSW
@FirmamentTSW 11 ай бұрын
neato!! learned a lot from how you gradually get the final solution.
@wintersol9921
@wintersol9921 11 ай бұрын
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 11 ай бұрын
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 11 ай бұрын
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
@simonvutov7575
@simonvutov7575 11 ай бұрын
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 11 ай бұрын
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!
@shashwatkumar3079
@shashwatkumar3079 11 ай бұрын
Always watch till the end because no matter how complicated, this guy can make it simpler only a little concentration is needed.
@anthonyleong4238
@anthonyleong4238 11 ай бұрын
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.
@surajvalluru
@surajvalluru 11 ай бұрын
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.
@hamirmahal
@hamirmahal 11 ай бұрын
Neat-o! I appreciate the longer length videos. I think they're very helpful. Thank you for making them.
@satyamjha68
@satyamjha68 11 ай бұрын
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!!
@rahulsbhatt
@rahulsbhatt 11 ай бұрын
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!
@tenthlegionstudios1343
@tenthlegionstudios1343 11 ай бұрын
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!
@SanketBhat7
@SanketBhat7 11 ай бұрын
Neato!! As far as knowledge is gained and content is understandable, doesn't matter how long the video is .. Thanks for the video
@EvanKendrick-d8h
@EvanKendrick-d8h 11 ай бұрын
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.
@sachinsinghbhadoriya9523
@sachinsinghbhadoriya9523 11 ай бұрын
Neato! This was one of THE problems I was not able to get my head around! Thanks for all the good work!
@LakshyaSethi-g7w
@LakshyaSethi-g7w 11 ай бұрын
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!
@yaswanthkosuru
@yaswanthkosuru 11 ай бұрын
finally after spent hours i cant able to do after seing sliding window pattren + dp i came up with solution within seconds
@pritz9
@pritz9 11 ай бұрын
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 !
@krishsharvesh8082
@krishsharvesh8082 11 ай бұрын
Neato! I actually didn't grasp everything you just told, maybe i need to review dp again , anyways great teaching as always
@mire5234
@mire5234 11 ай бұрын
This is ridiculously hard. I cannot imagine someone coming up with this solution during the interview.
@tkncompsci9353
@tkncompsci9353 11 ай бұрын
Neato!! Excellent Explanation!! I like to watch your videos always whether I know the solution or not.
@weronikalinda4917
@weronikalinda4917 11 ай бұрын
Neato lol I always watch the whole thing because of your explanations and the path you show to actually get to the solution
@gitarowydominik
@gitarowydominik 11 ай бұрын
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 11 ай бұрын
total includes prev[N-K] so why is the result when subtracting negative?
@gitarowydominik
@gitarowydominik 11 ай бұрын
@@binh-nguyen-dbecause of calculating the total % MOD and the underflow of int type.
@StephanieJohnston-rt7rq
@StephanieJohnston-rt7rq 7 ай бұрын
THANK YOU for this - I could not understand why one of my test cases was an extremely negative number
@michael._.
@michael._. 11 ай бұрын
ngl but this is one of the best questions in Leetcode and Neetcode has nailed it down with yet another legendary video (neato)
@radon3894
@radon3894 11 ай бұрын
Another excellent video, appreciate the time to explain your thought process!
@robertyamasaki1807
@robertyamasaki1807 11 ай бұрын
neato, first time in a while just silencing everything and looking at the in depth solution
@PabloElBlanco
@PabloElBlanco 11 ай бұрын
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 11 ай бұрын
Neato! You explained things very easily. Great approach. Thank you for such solution
@evanhuang756
@evanhuang756 11 ай бұрын
Neato. I went with the DP solution at first .Sliding window optimization is great
@yashraj3005
@yashraj3005 11 ай бұрын
We love you neetcode
@abhishekkaintura6398
@abhishekkaintura6398 11 ай бұрын
the way you explain the problem is really appreciable
@saminhasan87
@saminhasan87 11 ай бұрын
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 8 ай бұрын
Genius solution with amazing explanation!
@sankalpchordia5245
@sankalpchordia5245 11 ай бұрын
We need another algorithms super hard course in the platform!!
@triputrafauzanhradji8005
@triputrafauzanhradji8005 11 ай бұрын
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.
@rohanthakur9159
@rohanthakur9159 11 ай бұрын
Neato!! Just looking at a 10 pages long editorial gave me headache. Thanks for saving me.
@hackytech7494
@hackytech7494 11 ай бұрын
Neato! Well explained as always ❤
@diegobarbieri7804
@diegobarbieri7804 11 ай бұрын
this video is amazing, really clever solution!
@ahasunos5914
@ahasunos5914 11 ай бұрын
Neato!! The way you approach the solution step by step ❤️
@meylyssa3666
@meylyssa3666 11 ай бұрын
Thank you for clear explanations!
@विक्रमचौहान-द2थ
@विक्रमचौहान-द2थ 11 ай бұрын
neato! I am a beginner so it was very hard for me but still, I watched the full video and learned a lot.
@lawlesslotus
@lawlesslotus 11 ай бұрын
neato! thanks for the explanation, I always jump to your channel whenever there's a Hard problem.
@AMakYu
@AMakYu 11 ай бұрын
Neato. Great explanation, but what a wild problem. I hope to never get asked to optimize a DP to this point....
@ridamkrishna
@ridamkrishna 11 ай бұрын
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
@varunpalsingh3822
@varunpalsingh3822 11 ай бұрын
neato!! it was a tough problem, but learned a lot, thanks
@squid84202
@squid84202 11 ай бұрын
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
@sidreddy7030
@sidreddy7030 11 ай бұрын
Neato! Needed you to come and save the day
@ameetasom832
@ameetasom832 11 ай бұрын
Neato!! loved the optimization part
@EduarteBDO
@EduarteBDO 11 ай бұрын
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
@phuongnguyenhuynhanh7462
@phuongnguyenhuynhanh7462 11 ай бұрын
damn, i solved daily problems everyday and your video is always the highlight of my day
@anirbansarkar4189
@anirbansarkar4189 11 ай бұрын
superb explanation and approach
@jacquelinejan5898
@jacquelinejan5898 11 ай бұрын
Neato~Your videos have always helped me so much when practicing the problems!
@ElliuHuang
@ElliuHuang 11 ай бұрын
neato! thanks for going through all the steps to solve the problem
@jiteshpahwa266
@jiteshpahwa266 11 ай бұрын
@NeetCodeIO you left a condition while subtracting from the total for C++ and Java users: if(total
@kartik6968
@kartik6968 11 ай бұрын
Can you explain what does this do? I was getting the runtime error: signed integer overflow: -1533914095 + -675939082 cannot be represented in type 'int'
@tizekodnoon8305
@tizekodnoon8305 11 ай бұрын
Neato! Head hurting right now 😨
@piyushgupta7210
@piyushgupta7210 11 ай бұрын
neato! thanks man.. you really are making stuff easier for beginners
@timlu4734
@timlu4734 5 ай бұрын
neato! Really helpful video, as always. Save me a lot of time, thanks.
@blurryfca3
@blurryfca3 11 ай бұрын
This came on yesterday's Daily question!, neatoo
@qboff4468
@qboff4468 11 ай бұрын
Neato, you are the best, thank you😊
@ngoquangtrung234
@ngoquangtrung234 11 ай бұрын
Best explication.
@virgil246
@virgil246 11 ай бұрын
neeto~ Thanks for the smooth explanation!
@walkastray007
@walkastray007 11 ай бұрын
Neeto. I didn't make it to the solution, but I did think about the brute force one.
@leemin-gyu3236
@leemin-gyu3236 11 ай бұрын
Neato! Love the videos as well as the idea behind the different solutions :)
@aswinnath8580
@aswinnath8580 11 ай бұрын
neato! this is the hardest problem i've encountered in daily challenge.
@aryanikale7187
@aryanikale7187 11 ай бұрын
Thank you for this, definitely a hard problem
@johnj171
@johnj171 5 ай бұрын
God Father !!! I have made the video so farr you are amazing the king GODFATHER!!! love you content
@estifanosbireda1892
@estifanosbireda1892 11 ай бұрын
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?
@mohitkanodia5388
@mohitkanodia5388 11 ай бұрын
Neato !! Great explanation
@VanjeAv
@VanjeAv 10 ай бұрын
Wow thank you so much neetio :)!
@nishantketu2040
@nishantketu2040 11 ай бұрын
neato👍👍
@sprajosh
@sprajosh 11 ай бұрын
Neato ~ This is a definitely a big brain problem.
@arturremizov9296
@arturremizov9296 11 ай бұрын
Neato Thank you for your videos!
@ajaykumargogineni3391
@ajaykumargogineni3391 11 ай бұрын
neato!! Great explanation
@VasudevaK
@VasudevaK 11 ай бұрын
Perfect tutorial🤍
@rileysikes9285
@rileysikes9285 11 ай бұрын
neato!!!! Another great video
@Kugelblitz2b
@Kugelblitz2b 9 ай бұрын
neato 😭🤓
@MrKB_SSJ2
@MrKB_SSJ2 11 ай бұрын
25:40 DAMNNNNN NOTICED THE OPTIMIZATION. IMAGINE SOMEONE ASKS THIS IN THE INTERVIEW MANNN
@krateskim4169
@krateskim4169 11 ай бұрын
Hey neato it was a great video with an awesome explanation
@swanv951
@swanv951 11 ай бұрын
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)
@art4eigen93
@art4eigen93 11 ай бұрын
neato! but repeating the whole again, and again.
@sunilswizy8233
@sunilswizy8233 11 ай бұрын
super explanation neato!!!
@nikhil199029
@nikhil199029 8 ай бұрын
at 12:28, why are donig res = res+ (count(n-1,k-1))?
@rikthecuber
@rikthecuber 11 ай бұрын
Thanks for the soln Neato!
@aswathchandrasekar2917
@aswathchandrasekar2917 11 ай бұрын
Neato. Nice explanation. But have to come back to it later ;(
@AbdulrahmanEgy
@AbdulrahmanEgy 11 ай бұрын
super neatooo!🔥
@hikmetdemir1032
@hikmetdemir1032 11 ай бұрын
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
@MP-ny3ep
@MP-ny3ep 11 ай бұрын
Amazing explanation !! Neato 😆😆
@prateekgupta1417
@prateekgupta1417 11 ай бұрын
Neato! Definitely a hard problem
@yuxiangwang963
@yuxiangwang963 11 ай бұрын
Neato, really a HARD one!
@bhavyagautam8036
@bhavyagautam8036 11 ай бұрын
Neato! Loved your solution.
@ronbuchanan5432
@ronbuchanan5432 11 ай бұрын
Kudos to Neato! (don't you have video statistics though? haha)
@aniruddhachaki7165
@aniruddhachaki7165 11 ай бұрын
neato! it's 12:48 am here!
@ankurbose7672
@ankurbose7672 11 ай бұрын
Neato!!! How long did it take for you to get to the optimal solution on your own? Just curious.
@nooobody2751
@nooobody2751 11 ай бұрын
neato ! you are the GOAT. Thanks a lot.
@Cheng-K
@Cheng-K 11 ай бұрын
Neato! 🧠
@insaeq
@insaeq 11 ай бұрын
great explanation!
@AdenGolden
@AdenGolden 11 ай бұрын
number of permutations of length n with k inversions is the same as the number of permutations of length n with a major index equal to k. class Solution: def kInversePairs(self, n: int, k: int) -> int: MOD = 10 ** 9 + 7 dp = [[0] * (k + 1) for _ in range(n + 1)] dp[1][0] = 1 for i in range(2, n + 1): cumulative = 0 for j in range(k + 1): cumulative += dp[i - 1][j] if j >= i: cumulative -= dp[i - 1][j - i] dp[i][j] = cumulative % MOD return dp[n][k]
@Kaviarasu_NS
@Kaviarasu_NS 11 ай бұрын
neato!! big brain solutions ❤
@erminiottone
@erminiottone 11 ай бұрын
I passed the OJ with the first recursive solution in C++ with TC O(n*k^2) 😅
Greatest Common Divisor Traversal - Leetcode 2709 - Python
24:30
Hilarious FAKE TONGUE Prank by WEDNESDAY😏🖤
0:39
La La Life Shorts
Рет қаралды 44 МЛН
Student Attendance Record II - Leetcode 552 - Python
27:10
NeetCodeIO
Рет қаралды 10 М.
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,3 МЛН
Freedom Trail - Leetcode 514 - Python
25:18
NeetCodeIO
Рет қаралды 14 М.
Minimum Cost For Tickets - Leetcode 983 - Python
22:46
NeetCodeIO
Рет қаралды 5 М.
Python laid waste to my C++!
17:18
Sheafification of G
Рет қаралды 174 М.
Minimum Falling Path Sum II - Leetcode 1289 - Python
31:44
NeetCodeIO
Рет қаралды 9 М.
Clean Code is SLOW But REQUIRED? | Prime Reacts
28:22
ThePrimeTime
Рет қаралды 332 М.
When Optimisations Work, But for the Wrong Reasons
22:19
SimonDev
Рет қаралды 1,1 МЛН
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 183 М.