FastPrepProrated Monthly Subscription Charge

Prorated Monthly Subscription Charge

Clipboard Health logoClipboard Health● EasyFULLTIMEOA
Learn

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[]) → int

Examples

Example 1

daysInMonth = 30monthlyPriceCents = 3000activatedDay = [1,16]deactivatedDay = [30,30]return = 4500

One 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.
See Clipboard Health hiring insights
public int monthlyCharge(int daysInMonth, int monthlyPriceCents, int[] activatedDay, int[] deactivatedDay) {
    // Return the rounded monthly charge in cents.
}
daysInMonth30
monthlyPriceCents3000
activatedDay[1,16]
deactivatedDay[30,30]
expected4500
Checking account…