Goldman Sachs | Phone | Cheapest Price
Anonymous User
2335

Assume there are many sellers and you have to find the cheapest price at any one time.
a. The beginning and ending time/date will be given for each scenario and the goal is to have an algorithm that can generate the cheapest price a seller is offering.
b. So for example: For the dates of 1-3 Jan and 2-5 Jan. Find out the cheapest price the seller is giving between those dates

How to solve this efficiently?

Input:

arr = [{ startTime: 1, endTime: 5, price: 20 }, { startTime: 4, endTime: 6, price: 30 }, { startTime: 5, endTime: 8, price: 10 }]

Result:

arr = [{ startTime: 5, endTime: 8, price: 10 }, { startTime: 1, endTime: 4, price: 20 }, { startTime: 4, endTime: 5, price: 30 }]
Comments (2)