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
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
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