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.
Easy Approach by adding the values and assigning the index of each order to retrive based on their priority and then sorting the result based on the 2nd element in the summed array by using lambda function and then iterating through that sorted array in order to retrieve the order priority list and then returning it in type of res. Hope you understand!! Happy Coding!!
def jimOrders(l):
sum_l = sorted([[sum(j),i+1] for i,j in enumerate(l)], key = lambda x: x[0])
res = [ i[1] for i in sum_l]
return res
`
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Jim and the Orders
You are viewing a single comment's thread. Return to all comments →
Easy Approach by adding the values and assigning the index of each order to retrive based on their priority and then sorting the result based on the 2nd element in the summed array by using lambda function and then iterating through that sorted array in order to retrieve the order priority list and then returning it in type of res. Hope you understand!! Happy Coding!!