Calculate Effective Pricing Adjustments
Airbnb hosts often apply various pricing rules to their listings for specific date ranges, such as seasonal discounts, weekend surcharges, or event-specific pricing. These rules can overlap, and when they do, their effects combine. Your task is to process a list of such pricing adjustment intervals and determine the net effective adjustment for every contiguous period of time.
Given a list of pricing adjustment intervals, each defined by a start date, an exclusive end date, and an integer adjustment value, you must:
Input:
adjustments: An array of arrays, where each inner array [start, end, value] represents a pricing adjustment interval.
start: An integer representing the inclusive start day of the adjustment.end: An integer representing the exclusive end day of the adjustment. (i.e., the adjustment applies up to, but not including, end).value: An integer representing the absolute adjustment amount (e.g., +10 for a $10 increase, -5 for a $5 discount).Output:
An array of arrays, effectiveAdjustments, where each inner array [effectiveStart, effectiveEnd, totalValue] represents a non-overlapping interval with its aggregated adjustment value.
effectiveStart in ascending order.effectiveEnd is exclusive, matching the input interval semantics.adjustments is empty, return an empty array.start and end dates can be very large integers, implying that a direct array/map indexed by day is not feasible.Examples
Example 1
Input:
adjustments = [[0, 5, 10], [3, 7, -5]]
Output:
[[0,3,10],[3,5,5],[5,7,-5]]
Note:
Days [0,3) have only +10. Days [3,5) have +10 and -5, totaling +5. Days [5,7) have only -5.
Example 2
Input:
adjustments = [[1, 4, 10], [2, 5, -5], [3, 6, 20]]
Output:
[[1,2,10],[2,3,5],[3,4,25],[4,5,15],[5,6,20]]
Note:
Events at day 1: +10. Day 2: +10-5=5. Day 3: +10-5+20=25. Day 4: -5+20=15. Day 5: +20.
Example 3
Input:
adjustments = [[0, 10, 5], [2, 8, -5]]
Output:
[[0,2,5],[2,8,0],[8,10,5]]
Note:
Days [0,2) have +5. Days [2,8) have +5 and -5, totaling 0. Days [8,10) have only +5.
Constraints
0 <= adjustments.length <= 10^5[start, end, value] in adjustments:
0 <= start < end <= 10^9-1000 <= value <= 1000start >= end (assume valid intervals are provided).Loading editor...