Тёмный

Minimize Maximum of Array - Leetcode 2439 - Python 

NeetCodeIO
Подписаться 129 тыс.
Просмотров 17 тыс.
50% 1

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
Solving Leetcode 2439 - Minimize Maximum of Array, today's daily leetcode problem on April 4th.
🥷 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/minimiz...
0:00 - Read the problem
0:30 - Drawing Explanation
7:55 - Coding Explanation
leetcode 2439
#neetcode #leetcode #python

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

 

1 июн 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 47   
@abhayphanse9509
@abhayphanse9509 Год назад
I have almost 400 questions on leetcode now and still got stuck at this , it is in my opinion a one off problem (it is what it is). Dont be discouraged if not able to solve this , keep grinding . We always have neetcode to help us out
@16avikasgupta70
@16avikasgupta70 Год назад
Same I have also solved around 300 and was stuck how to approach andin mind i was stuck with max heap approach
@Cygx
@Cygx Год назад
Brilliant solution and explanation!
@annoyingorange90
@annoyingorange90 Год назад
im on 600 and still shit bro lol
@minhdang5132
@minhdang5132 Год назад
> 500 here, and still cannot solve it
@tarnished3571
@tarnished3571 Год назад
550 and also got stuck at this problem
@NitinSingh-yc7rg
@NitinSingh-yc7rg Год назад
he came when we needed the most
@scresat
@scresat Год назад
with every new problem, I'm getting intuition if I will be able to solve it on my own or not. For this one, I came straight to you without writing a single thing on paper.
@akashsardar495
@akashsardar495 Год назад
I got upset when I could not come up with a Binary search approach as mentioned in the Hint section of the problem but after watching the first 3-4 mins of your video I was able to solve it. You are really great at breaking down complicated problem statements in their lucidest form 🙏🏻🙏🏻Thank u NeetcodeIO.
@effyzhang1281
@effyzhang1281 Год назад
I don't even understand the question to begin with, thanks so much for the video!!!
@MP-ny3ep
@MP-ny3ep Год назад
Thank you so much for the daily leetcode problems ! Helps a lot !!! Keep it up
@akifahmed9610
@akifahmed9610 Год назад
You have explained the solution so simply. Keep up the good work
@yoonkeunkoh9162
@yoonkeunkoh9162 Год назад
You are amazing. You explain this problem as if explaining to 7 years old student. Great Video
@netanelkomm5636
@netanelkomm5636 Год назад
Thank you so much, I actually thought of this idea but couldn't verify it for some reason myself. I watched your video and realized it was the same idea, so I implemented it and it worked. New sub!
@mirkelor
@mirkelor Год назад
After listening 2 min of your video, suddenly the solution occurred in my mind and I continued. It was precisely the same as yours. Thank you for clarifying as best as every time
@ayushdhiman9378
@ayushdhiman9378 Год назад
Only video that helped me understand the problem fully thank you !!❤❤
@mrmcpherson2722
@mrmcpherson2722 Год назад
Right on time! Thank you!
@krateskim4169
@krateskim4169 Год назад
how did you even come with this type of intuition, its amazing
@amandubey5287
@amandubey5287 Год назад
class Solution: def minimizeArrayValue(self, nums: List[int]) -> int: sum_val = nums[0] count = 1 max_val = nums[0] for r in range(1,len(nums)): sum_val+=nums[r] count+=1 avg_val = math.ceil(sum_val/count) max_val = max(max_val,avg_val) return max_val
@bobbajahnavi7540
@bobbajahnavi7540 Год назад
thank you so much for the vedio it helps me a lot........
@harshitbisen8924
@harshitbisen8924 Год назад
why a similar logic in c++ fails a test case? Code: class Solution { public: int minimizeArrayValue(vector& nums) { int total = nums[0]; int res = nums[0]; int n = nums.size(); for(int i = 1;i < n;i++){ total += nums[i]; int t = ceil(total/(i+1)); res = max(res,t); } return res; } }; Test case: nums = [13,13,20,0,8,9,9] Output 15 Expected 16
@NeetCodeIO
@NeetCodeIO Год назад
My guess is that your ceil() method call is not working, since in C++, dividing integers results in an integer rather than a float. You prob want to cast total as a float or double before dividing
@yashgupta6797
@yashgupta6797 Год назад
use int t = ceil (double(total)/double(i+1)); bcz you used int/int which will always give u int only no advantage of ceil
@yashgupta6797
@yashgupta6797 Год назад
also used long long for total else overflow may occur
@scresat
@scresat Год назад
Correct way is (int) ceil((double) total/(i+1)) Casting value inside the ceil to double, then casting the return of ceil to int since ceil returns a double value.
@HoanNguyen-fc8vb
@HoanNguyen-fc8vb Год назад
Very nice! Thanks !
@mostafaahmed-fj8ji
@mostafaahmed-fj8ji Год назад
good work , thank you
@user-xu4qv9mt7e
@user-xu4qv9mt7e Год назад
Really good video
@fane1159
@fane1159 Год назад
please also solve this using binary search ,else this is also a fantastic way
@nisaacdz
@nisaacdz Год назад
thanks
@foobar69
@foobar69 5 месяцев назад
why is average working here? why isn't median being used? i thought of something along these lines then went ahead with median and got WA.
@VIVEKSINGH-pc4lb
@VIVEKSINGH-pc4lb 10 месяцев назад
you are genious
@twonwon3595
@twonwon3595 Год назад
I one question about this in the explanation that they have provided what if we do this operation one more time and select i=3 then the array will become [5,5,3,4] So wouldn't this 4 be the minimum value ? I think I am missing something here
@sandagolcea4966
@sandagolcea4966 Год назад
Stumbled upon the same, but: No, because we always get the overall array max, so overall max in the array is still 5 (see [5,5,3,4] ) even if we modify some other part to have a smaller max, it will make no difference.
@twonwon3595
@twonwon3595 Год назад
@@sandagolcea4966 yes when you put it this way it makes sense. Thanks for replying !
@Aabid_02
@Aabid_02 Год назад
I had compilation error @line 7 because there is to +i add in total ( total + i ) / ( i + 1 )) not sure how it running right there. Please check
@infiniteloop5449
@infiniteloop5449 Год назад
why are you adding i to total? it should be total/(i+1)
@naive-fleek7420
@naive-fleek7420 Год назад
dayummmm love u
@brm266
@brm266 6 месяцев назад
I came up with a solution in 35 minutes
@shubhamraj25
@shubhamraj25 Год назад
Tricky one, yeah
@sandagolcea4966
@sandagolcea4966 Год назад
Don't understand what you mean by "we can't move values to the left" / right. 🤔
@yashjoon3889
@yashjoon3889 Год назад
moving a value to left means decreasing the current value and increasing the left value. Imagine it like a number flew towards the left hence reduced the current value by 1 and increased the left value by 1.
@cc-to2jn
@cc-to2jn 5 месяцев назад
man i tried heap sol, but couldnt get it to pass. Not sure where the error is: class Node: def __init__(self,val,left=None,right=None): self.val=val self.left=left self.right=right def __lt__(self, other): return self.val int: heap=[] curr=h=Node(float('inf')) for j in range(len(nums)): node=Node(-nums[j]) curr.right,node.left=node,curr heappush(heap,node) curr=curr.right out=heap[0].val while True: if heap[0].left==h or heap[0].val+1==0: #cant make smaller return -heap[0].val node=heappop(heap) node.val+=1 node.left.val-=1 heappush(heap,node) if heap[0].val>=out: out=heap[0].val else: break return -out Testcase: [13,13,20,0,8,9,9] output: 15 Expected: 16
Далее
Minimize Deviation in Array - Leetcode 1675 - Python
20:40
Leetcode 149 - Maximum Points on a Line - Python
8:14
Tragic Moments 😥 #2
00:30
Просмотров 4 млн
Super sport😍🔥
00:14
Просмотров 1,6 млн
Прилетели в Дубай
00:17
Просмотров 75 тыс.
Find Peak Element - Leetcode 162 - Python
11:02
Просмотров 30 тыс.
How I would learn Leetcode if I could start over
18:03
Просмотров 101 тыс.
Design HashSet - Leetcode 705 - Python
11:57
Просмотров 19 тыс.
3 Tips I’ve learned after 2000 hours of Leetcode
0:44
Tragic Moments 😥 #2
00:30
Просмотров 4 млн