Nice solution, we can have only three possibilites[ (min-0),(min-1),(min-2)],,,,,(min-5) will lead to recurrence.... Why? because in question we are given [1,2,5]... This works for me-> int equal(vector arr) { vector possibilities(3); // Start with the minimum element int minimum = *min_element(arr.begin(),arr.end()); for (int i = 0; i < 3; i++) { for (int k : arr) { int diff = k - minimum; int stepsRequired = diff / 5 + (diff % 5) / 2 + ((diff % 5) % 2) / 1; possibilities[i] += stepsRequired; } minimum--; } // Return the minimum number out of all the possibilities return *min_element(possibilities.begin(),possibilities.end()); }
The range comes from the fact that you can either give 1, 2 or 5 chocolates. That's why you have to check all the possibilities in that range. We do not go past "min-4" because that will take 5 operations which is same as a single operation of giving 5 chocolates at once. Hope that helps.
If you reach ‘min-5’, then you will reach the same scenario you started with. Try to do a dry run and take away 5 chocolates, you will find yourself in a recurrence :)
@@nikoo28 take 1 from first ==> 1 operation take 5 from second ==> 2 operation take 5 from third ==> 3operation Not sure if 0,0,0 can be the answer or not.
@@aakrandan 3 is the correct answer. If you try to run the code I have provided, it will give you the answer 3. I think from my explanation you missed the part to check for a range of "min" to "min - 4"
Thanks for your feedback, in an effort to constantly improve please let me know what kind of issues did you face. I will try to improve it in my next video.
You have nothing to do with his voice, he is doing a great job let him continue you just focus on your voice.we don't come here to judge his voice but to understand his problem solving technique.
@@sheikhyawar2628 BTW brother, I never commented on his problem solving skills ik he's a good problem solver And moreover I'll comment what I feel @Study Algorithms pleas do use autotuned voice it's really difficult to listen Hope you understand:)
Thanks brother! Finally I understood it. The visuals and explanation were really good.
voice(not so quick not so slow moderate)& explanation are on 🔥
Nice solution, we can have only three possibilites[ (min-0),(min-1),(min-2)],,,,,(min-5) will lead to recurrence.... Why? because in question we are given [1,2,5]...
This works for me->
int equal(vector arr) {
vector possibilities(3);
// Start with the minimum element
int minimum = *min_element(arr.begin(),arr.end());
for (int i = 0; i < 3; i++) {
for (int k : arr) {
int diff = k - minimum;
int stepsRequired = diff / 5 + (diff % 5) / 2 + ((diff % 5) % 2) / 1;
possibilities[i] += stepsRequired;
}
minimum--;
}
// Return the minimum number out of all the possibilities
return *min_element(possibilities.begin(),possibilities.end());
}
Bro, Thanks a lot, finally understood the solution
My first thought was solving this through BFS
Please explain more about the optimal solution being present in [min, min-4] range
The range comes from the fact that you can either give 1, 2 or 5 chocolates. That's why you have to check all the possibilities in that range. We do not go past "min-4" because that will take 5 operations which is same as a single operation of giving 5 chocolates at once.
Hope that helps.
@@nikoo28 Finally I understood.. Thanks a lot, brother!
well explained.
Heya, I'm still confused about min to min-4.
your explanation was great, it really helped me
Great Work !!!!
great explaination Thx alot !
That is genius!
very interesting explanation
Very nice bro 😃 Well explained & animation made it so easy
Thank You!!
wow this was really good thank you!!!
Thank you for this explanation!
what a explanation man
Great video :) 😊
i don't understand why only till min-4 is considered
very detailed explanations
Very helpful!!
how you come to know that min will go till min-4??
That is because she can give a maximum of 5 chocolates. If she was able to give 8 chocolates, then you would have to check till 7.
@@nikoo28 This is a vital information, should have mentioned in the description.
@@aakrandan This information is mentioned in the problem description. :)
@@nikoo28 No where mentioned max of 5 chocolates can be distributed in pblm statement I have checked it
Nicely explained
14:05 can someone please explain to me how is (minimum - 5) the same scenario??
it is like dividing in groups of 5. the scenario will be same if it is 30 or 25 or 35
I had the same doubt on watching this video…
Thank you
when we reach min-5 then how it will be same scenario ??(14:02)
If you reach ‘min-5’, then you will reach the same scenario you started with.
Try to do a dry run and take away 5 chocolates, you will find yourself in a recurrence :)
bruh i have a doubt what if min=2,then will the still continue till it calculates min-4
yes…you need to calculate every possible min. Otherwise how will you know that min =2?
Don’t understand the Min to min -4 logic
according to algorith ans to 1 5 5 is 4 but the true ans is 3
Can you describe the 3 steps to make the distribution equal?
Adding 5
6 10 5
Adding 5
11 10 10
Adding 1
11 11 11
@@nikoo28 take 1 from first ==> 1 operation
take 5 from second ==> 2 operation
take 5 from third ==> 3operation
Not sure if 0,0,0 can be the answer or not.
@@aakrandan 3 is the correct answer. If you try to run the code I have provided, it will give you the answer 3.
I think from my explanation you missed the part to check for a range of "min" to "min - 4"
consider min from [min,min-4]
Worst voice ever heard :)
Thanks for your feedback, in an effort to constantly improve please let me know what kind of issues did you face.
I will try to improve it in my next video.
You have nothing to do with his voice, he is doing a great job let him continue you just focus on your voice.we don't come here to judge his voice but to understand his problem solving technique.
@@sheikhyawar2628 BTW brother, I never commented on his problem solving skills ik he's a good problem solver
And moreover I'll comment what I feel
@Study Algorithms pleas do use autotuned voice it's really difficult to listen
Hope you understand:)