We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

You have to focus on the difference. If every other colleagues receive a chocolate (because you have the greatest number of chocolates) the difference between your number of chocolates and the colleagues number will decrease.

@decuqa I have understood how the reduction will work. But i am unable to realise the same answer using the increment algo. For ex: 2 5 5 5 5 5, the operation count would be 6 as we reduce it to 0. But how in just 6 operations we can achieve this using increment technique which is our real problem statement. So, how exactly they are same in real?

Thanks. Got it.
But there is an cal error in your operations. Instead of 12 12 12 (19) 19 19, it should be 12 12 12 (17) 17 17.
Therefore, finally it would be 27 27 27 27 27 27.

logic is about making equal not zero.So in 2 5 5 5 5 5.If we reduce 3 from all 5 we left with each having 2 chocolate and that's what we want equal chocolates.

Thanks.But I got some other method which would solve by 4 operations please suggest any loop holes in my metghod.
step 1:place the values in the list
step 2:[1,3,5] are the possible ways to give chocolates
step 3: calculate minimum_of_list and maximum_of_list and index where maximum_of_list is present in list(if we have multiple maximum_of_list it has to return first_index)
step 4:diff = maximum_of_list - minimum_of_list
step 5:add the diff to all the list elements except to maximum_of_list
step 6:repeat step 3 to step 5 until all the values are equal in alist
Example:
(x):assume x is a small value
[x]:assume x is maximum_of_list
2 5 5 5 5
(2) [5] 5 5 5
(5) 5 [8] 8 8
(8) 8 8 [11] 11
(11) 11 11 11 [14]
14 14 14 14 14

## Equal

You are viewing a single comment's thread. Return to all comments →

hey namdx, could you explain the concept of how giving chocolate bars to all but one is equivalent to taking chocolate bar from 1 only.

You have to focus on the difference. If every other colleagues receive a chocolate (because you have the greatest number of chocolates) the difference between your number of chocolates and the colleagues number will decrease.

@decuqa I have understood how the reduction will work. But i am unable to realise the same answer using the increment algo. For ex: 2 5 5 5 5 5, the operation count would be 6 as we reduce it to 0. But how in just 6 operations we can achieve this using increment technique which is our real problem statement. So, how exactly they are same in real?

(2) 5 5 5 5 5

2 (7) 7 7 7 7

7 7 (12) 12 12 12

12 12 12 (19) 19 19

19 19 19 19 (24) 24

24 24 24 24 24 (29)

29 29 29 29 29 29

It's a same choice.

Thanks. Got it. But there is an cal error in your operations. Instead of 12 12 12 (19) 19 19, it should be 12 12 12 (17) 17 17. Therefore, finally it would be 27 27 27 27 27 27.

Possible in 5 step.

You Miss this condition

you give chocolate bars to all but chosen one.so you wont able to give chocolates to all at once.They should really bold this in the question. I didn't realize this making the problem seem very hard for me.

In second step, U have added 3, but addition of 1, 2 and 5 is ony possible

logic is about making equal not zero.So in 2 5 5 5 5 5.If we reduce 3 from all 5 we left with each having 2 chocolate and that's what we want equal chocolates.

12 12 12 (19) 19 19 19 19 19 19 (24) 24 ???

we can end it at 13 13 13 13 13 13 also but operations required are 6 only.

Thanks.But I got some other method which would solve by 4 operations please suggest any loop holes in my metghod. step 1:place the values in the list step 2:[1,3,5] are the possible ways to give chocolates step 3: calculate minimum_of_list and maximum_of_list and index where maximum_of_list is present in list(if we have multiple maximum_of_list it has to return first_index) step 4:diff = maximum_of_list - minimum_of_list step 5:add the diff to all the list elements except to maximum_of_list step 6:repeat step 3 to step 5 until all the values are equal in alist Example: (x):assume x is a small value [x]:assume x is maximum_of_list 2 5 5 5 5 (2) [5] 5 5 5 (5) 5 [8] 8 8 (8) 8 8 [11] 11 (11) 11 11 11 [14] 14 14 14 14 14

Have you implemented this approach??

the ways to give choclates is {1,2,5} and not {1,3,5}

That's not what the problem states.

I guess you figured out that statement has changed since. It was {1,2,5} two months ago

You cannot add 3 to any number. # will be added as combination of 1 and 2 which leads to 2 operation. Eveny my approach was same but got it wrong.

Could you please tell me how to solve 1 2 3 4 5 6

somebody changed the problem to [1,3,5] from [1,2,5] but didn't change the solutions

Yup.

In bird culture that is considered a dick move

Spent a few hours debugging my solution before going to forum in desperation and reading this comment...

Has this been resolved now?

if the difference is other than 1,2,5 how will you proceed next??

This would have slow performance.

yup according to

edemohankrishna1

Shouldn't be 3 2 3 5 7 1) 7 8 10 (7) 2) 10 11 (10) 10 3) 11 (11) 11 11

How did you decide you need to add 2 for the first iteration and 5 for the second iteration ?

(2) 5 5 5 5 5 (5) 5 8 8 8 8 (8) 8 8 11 11 11 (11) 11 11 11 14 14 (14) 14 14 14 14 17 (17) 17 17 17 17 17

only 5 steps

Yeah, with the differene method, 5 is coming only. But, in the test case it is saying 6 steps

@singhavdeshk for 2 5 5 5 5 5 operartion count will not be 6 it will be 5 2 5 5 5 5 5 5 5 8 8 8 8 8 8 8 11 11 11 11 11 11 11 14 14 14 14 14 14 14 17 17 17 17 17 17 17

This case operation count : 5

Please let me know if I am doing something wrong..

@iam_byungwoo :

you are correct; for the input [2, 5, 5, 5, 5], a minimum of 5 operations will suffice.

However, @singhavdeshk enquired about a different input [2, 5, 5, 5, 5, 5], which requires a minimum of 6 operations.

Thank you for your answer.

for [2,5,5,5,5] need 4 opration

You should look at your answer again. How did you add a 3 in 1 single operation?

Looks like the proble statement has been updated. It now states that chocolates can be given in groups of 1, 3, or 5.

The answers are still for 1,2,5

you dont need 6 steps in reduction method.

in reduction method reduce all 5 to 2

so it will take 5 steps

and in increment method as @zabed_akbar said only 5 steps required

2 (5) 5 5 5 5

5 5 (8) 8 8 8

8 8 8 (11) 11 11

11 11 11 11 (14) 14

14 14 14 14 14 (17)

17 17 17 17 17 17

you can't add 3 in your 1st step .....as the problem stated she can give wither 5 or 2 or 1 at once to all but chosen one