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.
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
Take [2,3] and maxOperations = 5 and trace out. The answer is 1 but if you take the range as min then the answer would be 2 but the actual answer would be 1.
It is a standard binary search assignment/asnwer range search problem. No intuition required. Practice problems: Aggressive cow, Painters partition problem, book allocation problem, Capacity To Ship Packages Within D Days :)
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
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.
are u working in morgan's now?
to be honest first I thought this is a Priority queue Problem. Hats off to your explanation.
Welcome :)
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
python too! there was some bug in java :o thanks
Well explained !
But definitely, from our side we need to have the will and patience to learn and understand!
yepp :)
Great explanation !! Thanks
You’re welcome!
Nice explanation
Thanks! :)
God level explanation 🙏🙏🙏
Appreciate the love! 🙏
great explaination thank u
Welcome :)
you are the greatest
Thanks for your appreciation:)
Thank you sir :)
Welcome! :)
Thankyou :)
You're welcome 😊
Thank you
You're welcome!
why can't search space can be start=minimum_number in array and end=maximum_number in array?
Take [2,3] and maxOperations = 5 and trace out. The answer is 1 but if you take the range as min then the answer would be 2 but the actual answer would be 1.
what was your intuition for binary search? couldn't think of it
It is a standard binary search assignment/asnwer range search problem. No intuition required.
Practice problems: Aggressive cow, Painters partition problem, book allocation problem, Capacity To Ship Packages Within D Days
:)
Simple hai : jahan bhi MAX of MIN ya phir MIN of MAX dekho.
Think of binary search.
But my doubt is while solving this qsn for the first, how do we come to this solution !
You should have solved similar questions or else this will add to your learning :)
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
yes because 1 operation is required to make 2 bags each of 4 size :)
@@techdose4u so its like no matter the operations should be overflow the give size right ?
@top10z38 Thats why we are checking if total operations are > max operations :)
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.
It will always work provided enough problems experience. I wouldnt suggest to worry so much if you are preparing for interviews though :)