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.
It doesn't really matter.
Call the flowers [3,2,1].
A or B takes the most expensive flower, say A for argument.
A pays (1)3 = 3. Now the next most expensive flower could be purchased by A or B. If A purchases it, it will cost (2)2 = 4, but if B does it will cost (1)2 = 2, so B should purchase.
Now we need to buy the 1 flower, and both A and B have a coefficient of 2 now, so it doesn't matter who does. (You don't even have to keep track of people to solve the problem!)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Greedy Florist
You are viewing a single comment's thread. Return to all comments →
It doesn't really matter.
Call the flowers [3,2,1]. A or B takes the most expensive flower, say A for argument. A pays (1)3 = 3. Now the next most expensive flower could be purchased by A or B. If A purchases it, it will cost (2)2 = 4, but if B does it will cost (1)2 = 2, so B should purchase.
Now we need to buy the 1 flower, and both A and B have a coefficient of 2 now, so it doesn't matter who does. (You don't even have to keep track of people to solve the problem!)