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.
Well, what are we doing, and is what we're doing greedy?
Because the coefficients are constantly increasing (at a rate of 1 per k purchases), we purchase the most expensive flowers first in order to minimize cost, rotating people to hold coefficients down as long as possible.
Assuming this rotation of customers, the algorithm optimizeses at each step by choosing to purchase the most expensive remaining flower.
Recall that this is the definition of a greedy algorithm.
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 →
Well, what are we doing, and is what we're doing greedy?
Because the coefficients are constantly increasing (at a rate of 1 per k purchases), we purchase the most expensive flowers first in order to minimize cost, rotating people to hold coefficients down as long as possible.
Assuming this rotation of customers, the algorithm optimizeses at each step by choosing to purchase the most expensive remaining flower.
Recall that this is the definition of a greedy algorithm.