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.

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

It doesn't give optimal solution in all cases.
TC => 2 5 5 5 5 5
expected=> 6
actual=>10

I implemented it so I know. The problem occurs because we are always adding to lower elements which causes problems as it is not proved to be safe move.

## Equal

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

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.

It doesn't give optimal solution in all cases. TC => 2 5 5 5 5 5 expected=> 6 actual=>10

I implemented it so I know. The problem occurs because we are always adding to lower elements which causes problems as it is not proved to be safe move.

Also it give TLE.