Find cheapest price for X number of days
Posted
by user76152
on Stack Overflow
See other posts from Stack Overflow
or by user76152
Published on 2010-05-03T12:52:45Z
Indexed on
2010/05/03
12:58 UTC
Read the original article
Hit count: 369
Hey 'FLow.
I have a technical challenge for you regarding an algorithm.
Lets say I have this list of days and prices:
List<ReservationPrice> prices = new List<ReservationPrice>();
prices.Add(new ReservationPrice { NumberOfDays = 1, Price = 1000 });
prices.Add(new ReservationPrice { NumberOfDays = 2, Price = 1200 });
prices.Add(new ReservationPrice { NumberOfDays = 3, Price = 2500 });
prices.Add(new ReservationPrice { NumberOfDays = 4, Price = 3100 });
prices.Add(new ReservationPrice { NumberOfDays = 7, Price = 4000 });
What I would like to able to do now is:
give me the best price from the list based on a number of days.
So if ask for 3 days the best price from the list is from child one (1000) and two (1200), but there are of course different combinations you would have to try out at first. How would an algorithm that found the best price from this list look like ?
Thank you!
© Stack Overflow or respective owner