Комментарии:
what was your intuition for binary search? couldn't think of it
Ответитьhindi bolne mai sharam aati hai kya
Ответить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
Nice explanation
ОтветитьGreat explanation !! Thanks
ОтветитьThank you
Ответитьgreat explaination thank u
Ответитьwhy can't search space can be start=minimum_number in array and end=maximum_number in array?
ОтветитьGod level explanation 🙏🙏🙏
Ответить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.
you are the greatest
ОтветитьThank you sir :)
ОтветитьThankyou :)
ОтветитьWell explained !
But definitely, from our side we need to have the will and patience to learn and understand!
But my doubt is while solving this qsn for the first, how do we come to this solution !
Ответитьto be honest first I thought this is a Priority queue Problem. Hats off to your explanation.
Ответить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
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.
Ответить