Last Stone Weight II - Leetcode 1049 - Python

  Рет қаралды 16,772

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 37
@iamsmitthakkar
@iamsmitthakkar 10 ай бұрын
Just fyi: you don't have to have ceil(total // 2), it will work without ceil function as well Goes without saying - great explanation. Thank you for your videos.
@CS_n00b
@CS_n00b 8 ай бұрын
This is too hard for a medium imo
@iamnoob7593
@iamnoob7593 3 ай бұрын
Got it thank you Neetcode.
@Mr.Bombastic-tl5ic
@Mr.Bombastic-tl5ic 11 ай бұрын
great explanation
@Mr.Bombastic-tl5ic
@Mr.Bombastic-tl5ic 11 ай бұрын
Nice question
@rajshah9129
@rajshah9129 Ай бұрын
when i saw this problem instantly max heap solution came in my mind removing top 2 element and adding their difference again in max heap and returning last remaining element from max heap? how can i come up with this like max heap solution will not work and intuition for your solution will work by reading question due to which part i can understand?
@parthbhatia341
@parthbhatia341 5 ай бұрын
I hate this question it tricks you into thinking it is a greedy problem.
@saitejachebolu4798
@saitejachebolu4798 Жыл бұрын
It can be done with meet in the middle algorithm
@parashararamesh4252
@parashararamesh4252 Жыл бұрын
Would a greedy approach work? Have a Max heap and smash the top two and put the resultant back into the max heap. Can't think of a problem edge case where this fails
@hamzaislam101
@hamzaislam101 Жыл бұрын
Yeah I also thought of this
@izumishark
@izumishark Жыл бұрын
7,7,8,8,14,16
@hamzaislam101
@hamzaislam101 Жыл бұрын
@@izumishark got it 👍
@m.kamalali
@m.kamalali Жыл бұрын
Try this [31,26,33,21,40]
@nikhil199029
@nikhil199029 Жыл бұрын
​@@m.kamalali yes it will work
@theexplorer9012
@theexplorer9012 4 ай бұрын
nice bra keep up
@sheikhmkrifat7749
@sheikhmkrifat7749 4 ай бұрын
My first thought was greedy, but it doesnt work , i dont know why.........
@nikhil199029
@nikhil199029 Жыл бұрын
Why aren't we using heapsort?
@albertd7658
@albertd7658 Жыл бұрын
Because instead of smashing the largest/smallest stones in the array (Last Stone Weight I), we're smashing them to yield the minimum result. You could try to do heapsort on the first test case and it gives you a different result than 1 I believe.
@tanishq2766
@tanishq2766 Жыл бұрын
No, in the second testcase it does though@@albertd7658
@dhivakarsomasundaram21
@dhivakarsomasundaram21 Жыл бұрын
TypeError: '
@yg1095
@yg1095 Жыл бұрын
You might not be returning dp[(i, total)] at the end of the function
@dhivakarsomasundaram21
@dhivakarsomasundaram21 Жыл бұрын
@@yg1095 Nah man I copied and pasted as he posted here. inside the function of this variable dp[(i, total)] failed to evaluate the min(>/
@vipsvips3213
@vipsvips3213 Ай бұрын
i love you
@deadsippy
@deadsippy Ай бұрын
this comment sent me for some reason 🤣🤣🤣
@ary_21
@ary_21 Жыл бұрын
I have a doubt , i know it happens internally but still wanna know whats the time complexity of pushing any element x in a heap of size k?
@ducthinh2412
@ducthinh2412 Жыл бұрын
Pushing an element to a heap of size K is O(logK)
@Alec____
@Alec____ 5 ай бұрын
It's O(log K) because log K is the height of the balanced tree that represents the heap and worst case you have to move it up all the way from a leaf to the root (when you insert, you're inserting at the end of the array representing the heap, so it's a leaf)
@vijayjagan8198
@vijayjagan8198 Жыл бұрын
can you cover mcm pattern
@mithunverma225
@mithunverma225 Жыл бұрын
sir please create a playlist for these leetcode problems
@supercarpro
@supercarpro Жыл бұрын
Did you look at his channel? He has multiple playlists. There's also a website, with all problems listed and courses he offers
@huimingli9207
@huimingli9207 Жыл бұрын
1st, thanks for the daily upload
@StellasAdi18
@StellasAdi18 Жыл бұрын
That was tricky. Only genius like you can only come up in interview to realize it’s variation of 0/1 KP.
@sherkrduotrg1978
@sherkrduotrg1978 4 ай бұрын
none of these solutions ever make sense to me 😔
Find Duplicate Subtrees - Leetcode 652 - Python
14:33
NeetCodeIO
Рет қаралды 20 М.
Stone Game II - Leetcode 1140 - Python
18:40
NeetCodeIO
Рет қаралды 23 М.
Farmer narrowly escapes tiger attack
00:20
CTV News
Рет қаралды 11 МЛН
Увеличили моцареллу для @Lorenzo.bagnati
00:48
Кушать Хочу
Рет қаралды 8 МЛН
Ones and Zeroes - Leetcode 474 - Python
17:59
NeetCodeIO
Рет қаралды 11 М.
Remove Duplicates from Sorted Array II - Leetcode 80 - Python
12:19
Edit Distance - Dynamic Programming - Leetcode 72 - Python
21:00
Last Stone Weight - Priority Queue - Leetcode 1046 - Python
12:38
Minimize Maximum of Array - Leetcode 2439 - Python
9:50
NeetCodeIO
Рет қаралды 21 М.
New 21 Game - Leetcode 837 - Python
19:03
NeetCodeIO
Рет қаралды 13 М.
LeetCode - Last Stone Weight 2 (1049)
18:52
LeetCode Learning
Рет қаралды 10 М.
Farmer narrowly escapes tiger attack
00:20
CTV News
Рет қаралды 11 МЛН