My first instinct was greedy, pick the days where the sum of active image costs is highest and apply the discount there.
Model the problem as choosing a single day to apply the discount, since it can be used at most once. For each candidate day, compute the total cost as the sum of costs of images not running that day plus the discount price if any images are running, and take the minimum over all days. Use a sweep line or difference array to efficiently compute daily totals.
Pro tip: Clarify with the interviewer whether the discount is mandatory or optional; if optional, you must also consider the case of not using it. Also, remember to apply modulo only at the end to avoid precision issues.
Restate the problem to ensure you understand the constraints: n images, each with a cost and a date range, and a discount that can be applied exactly once on any day, replacing the total cost of running images that day with a flat discountPrice.
The goal is to minimize the total cost across all days. Since the discount is applied on exactly one day, the total cost is the sum of costs on all other days plus the discounted cost on the chosen day.
Use a difference array or sweep line to compute the total cost of running images for each day. For each image, add its cost to the start day and subtract it after the end day in the difference array, then prefix sum to get daily totals.
For each day, compute the total cost if the discount is applied that day: total cost of all days minus the daily cost of that day plus the discount price (if any images are running; otherwise, the discount might not apply). Take the minimum over all days.
Consider edge cases: no images running on a day, discount price higher than daily cost, and the possibility of not using the discount if it's optional. Finally, apply modulo 1,000,000,007 to the result.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.