Prorated Monthly Subscription Charge
Problem statement
Compute a customer's monthly subscription charge in cents. The subscription costs monthlyPriceCents per active user for a full month of daysInMonth days.
User i is active from activatedDay[i] through deactivatedDay[i], inclusive. An activation day of 0 means the user was already active before this month; a deactivation day of 0 means the user remains active after this month. Sum all prorated user charges, then round the final total to the nearest cent, with an exact half cent rounded up.
Function
monthlyCharge(daysInMonth: int, monthlyPriceCents: int, activatedDay: int[], deactivatedDay: int[]) → intExamples
Example 1
daysInMonth = 30monthlyPriceCents = 3000activatedDay = [1,16]deactivatedDay = [30,30]return = 4500One user is active all month and the other for 15 of 30 days.
Constraints
28 <= daysInMonth <= 31.0 <= monthlyPriceCents <= 10^7.activatedDay.length == deactivatedDay.length <= 100000.- Each nonzero day lies in the month, and each user's active interval is valid.