Ride Surge Pricing Engine

Medium ⏱ 12 min 58% acceptance ★★★★★ 4.7
Write fare(base, demand, supply) applying a surge multiplier of demand / supply clamped between 1.0 and 3.0 (never discount, never gouge past 3×), rounding the final fare to the nearest integer rupee. A supply of zero maxes the surge at 3.0.

Examples

Example 1
Input
fare(100, 150, 100)
Output
150
Explanation

Surge 1.5× applies.

Example 2
Input
fare(100, 50, 100)
Output
100
Explanation

Low demand still pays base fare — clamped at 1.0.

Constraints

  • Clamp to [1.0, 3.0].
  • supply == 0 → multiplier 3.0.

Topics

Business Logicdynamic pricing

Companies

UberOlaRapido

Hints

Hint 1

min(3.0, max(1.0, ratio)).

Hint 2

Guard the division first.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.