Minimum Limit of Balls in a Bag | Leetcode 1760

Minimum Limit of Balls in a Bag | Leetcode 1760

Techdose

54 года назад

5,139 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@vibhoragarwal2935
@vibhoragarwal2935 - 07.12.2024 07:22

what was your intuition for binary search? couldn't think of it

Ответить
@derek-c9e
@derek-c9e - 07.12.2024 07:55

hindi bolne mai sharam aati hai kya

Ответить
@top10z38
@top10z38 - 07.12.2024 08:21

operations += (num - 1) // penalty

i still dont get it .

consider num = 8 , penalty = 4

we are checking
= (8-1) // 4
= 1 -> this gives value as 1

but we can also divide 8 as 5,3 - 6,2 - 7,1 right . why are we only consider less than value

Ответить
@vinodpaluvuri54
@vinodpaluvuri54 - 07.12.2024 10:14

Nice explanation

Ответить
@JuicyM0N
@JuicyM0N - 07.12.2024 11:09

Great explanation !! Thanks

Ответить
@IT__RAJVEERSINGH
@IT__RAJVEERSINGH - 07.12.2024 11:20

Thank you

Ответить
@srikantkumar9860
@srikantkumar9860 - 07.12.2024 15:27

great explaination thank u

Ответить
@vooratharunkumar4704
@vooratharunkumar4704 - 07.12.2024 16:37

why can't search space can be start=minimum_number in array and end=maximum_number in array?

Ответить
@SumanDas-fx5vu
@SumanDas-fx5vu - 07.12.2024 16:43

God level explanation 🙏🙏🙏

Ответить
@manishbolbanda4614
@manishbolbanda4614 - 07.12.2024 17:50

Techdose is my goto channel for any DSA Problem. the way you explain the approach is super good.
i was part of Techdose batch in Oct-2022 and its worth the money - it really helped me crack Morgan's interview like a cup cake.
Thank you Surya for your contribution.

Ответить
@Bruce_Wayne1720
@Bruce_Wayne1720 - 07.12.2024 18:24

you are the greatest

Ответить
@sailendrachettri8521
@sailendrachettri8521 - 07.12.2024 19:25

Thank you sir :)

Ответить
@lohithaadapala6989
@lohithaadapala6989 - 07.12.2024 20:23

Thankyou :)

Ответить
@dhruthiaddagatla2959
@dhruthiaddagatla2959 - 07.12.2024 20:47

Well explained !

But definitely, from our side we need to have the will and patience to learn and understand!

Ответить
@dhruthiaddagatla2959
@dhruthiaddagatla2959 - 07.12.2024 20:48

But my doubt is while solving this qsn for the first, how do we come to this solution !

Ответить
@VISHALMISHRA-ff2ih
@VISHALMISHRA-ff2ih - 07.12.2024 22:14

to be honest first I thought this is a Priority queue Problem. Hats off to your explanation.

Ответить
@iffyaiyan8942
@iffyaiyan8942 - 08.12.2024 11:29

hey thanks for the explanation, there is some fix in the Python code, as some test cases failed

class Solution:
def canAssign(self, nums, max_val, operations):
count = 0
for ele in nums:
if ele > max_val:
# Calculate the number of operations needed to split the bag
count += (ele - 1) // max_val # Equivalent to ceil(ele / max_val) - 1
return count <= operations

def minimumSize(self, nums, max_operations):
low, high = 1, max(nums)
res = float('inf')

while low <= high:
mid = low + (high - low) // 2
if self.canAssign(nums, mid, max_operations):
res = mid
high = mid - 1
else:
low = mid + 1

return res

Ответить
@YouCodeRK
@YouCodeRK - 08.12.2024 12:52

How I can think like this for a tricky problem like this. I know Your answer may be 'Practice'. But it does not always work.

Ответить