Successful Pairs of Spells and Potions - Leetcode 2300 - Python
Vložit
- čas přidán 24. 07. 2024
- 🚀 neetcode.io/ - A better way to prepare for Coding Interviews
Solving Leetcode 2300 - Successful Pairs of Spells and Potions, today's daily leetcode problem on April 1st.
🥷 Discord: / discord
🐦 Twitter: / neetcode1
🐮 Support the channel: / neetcode
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
💡 DYNAMIC PROGRAMMING PLAYLIST: • House Robber - Leetco...
Problem Link: leetcode.com/problems/success...
0:00 - Read the problem
1:15 - Drawing Explanation
8:00 - Coding Explanation
leetcode 2300
#neetcode #leetcode #python
missed you more than my girlfriend, thanks for being in my life
A girlfriend has too many edge cases
Thank you ! Please keep doing the daily leetcode questions. They're very helpful/motivating,
when you do the leetcode daily questions I feel like I have backup😃
Thanks for that
Thanks Neetcode for the intuition. One small issue I had in my code is, I had my append statement in this way, --> res.append(len(potions[idx:])) I was hit with Time Limit Exceeded error. I then followed your approach and corrected with res.append(len(potions) - idx)) it worked for me. Just thought to share
I feel like I've reached a milestone. I didn't check your video before solving the problem and my solution was a sort + binary search like yours. OMG!!!!!!
Instead of declaring a new var "idx", we can simply use the left value. So when binary search is done, we have the furthest left value in "l". Therefore, we can simply append len(potions) - left to the result.
I'm so glad for those daily questions you solve .Keep it please .
This is the kind of question you hope you'll be asked at an interview, and not some obscure hard problem
Once again we welcome you back!!!!
You can count pairs , with this formula as well -> count += (r - mid + 1)
Actually, we don't need the idx, given the example in the video, {1, 2, 2, 2, 4}, the spell is 5, success is 10, and the last position for l is 1, which can just be used for counting the success, len - l is the result, this applies to any other cases as well. Please correct me if I was wrong.
Thank you!
NOTE: you can just use the left pointer instead of the idx variable
Please cover before Daily challenge also, scramble strings and pizza sum
This sum is pretty easy.
Blessed with another video from neetcode
Thanks for the daily
Amazing Explanation................
You can use l instead of idx
Thank you so much
Little reminder: nlogm + mlogm = (n+m)(logm), instead of n + m(logm). Anyway, you are awesome!🥰
Can you please upload a video for solving the problem "number of ways of cutting a pizza"?
thanyou for explaination
Heyy, I follow your solutions regularly ... mainly because they are most intuitive and easy to understand! But why didn't you upload the solution for leetcode daily challenge of 31st march: number of ways of cutting pizza ... It was a very beautiful question!
that bisect method is crazy in python!!
Yeah it def is, but almost feels like cheating.. I think for this problem in an interview, writing out the binary search would be better, but depends on the interviewer
@@NeetCodeIO you are right, it does feel like cheating but might impress the interviewer that you know something which he doesn't
thx, bro
this was very helpful. esspecialy how you explained the algo and also gives the BigO notation
missed you
U a Wizard God
why is the leetcode syntax coloring going a little crazy? I dont like it lol
I sell my wife so I can upgrade my computer to do more leetcodes
Don't know why it showing TLE at my end
in line 15 you might have missed the = sign
god bless you
thank you for this! :D helped a lot
First
maestro