Calculate charge with a single price override
Company: Crusoe
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
You are billing a customer based on *usage intervals* and a *single temporary price override*.
## Definitions
- A usage record is an interval `[start, end)` where `start` is inclusive and `end` is exclusive.
- `defaultPrice` is the price per unit time (e.g., per day) when no override applies.
- An override is:
- `override.period = [overrideStart, overrideEnd)`
- `override.price` = the price per unit time during the override period.
## Task
Given:
- `usageRecords: []Interval` (each `Interval` is `[start, end)`)
- `defaultPrice: int`
- `override: PriceOverride`
Compute the **total charge** across all usage time, where:
- Any portion of usage that overlaps `override.period` is billed at `override.price`.
- Any portion of usage outside `override.period` is billed at `defaultPrice`.
Return the total charge as an integer.
## Notes / Edge cases to handle
- Usage may be **fully outside**, **fully inside**, or **partially overlap** the override period.
- Assume inputs are valid (e.g., `start < end`, prices are non-negative).
- Clarify in your solution whether `usageRecords` can overlap each other; if they can, ensure you do not double-bill overlapping usage time (e.g., by merging first).
## Example (conceptual)
If `defaultPrice = 10`, override period is `[2, 6)` with `override.price = 5`, and a usage record is `[1, 4)`, then:
- `[1,2)` billed at 10
- `[2,4)` billed at 5
Quick Answer: This question evaluates understanding of interval arithmetic, overlap detection and aggregation for time-based billing, plus careful edge-case handling of inclusive/exclusive boundaries within the Coding & Algorithms domain.