Frontend School

Airbnb Host's Strategic Pricing

DSA
hard

Airbnb Host's Strategic Pricing

Hard
Dynamic Programming
1D DP

Overview

As an Airbnb host, optimizing your pricing strategy is crucial for maximizing revenue while maintaining guest satisfaction. This problem simulates a scenario where you need to decide between standard and premium pricing for your listing over a series of days, balancing higher revenue potential with strategic cooldown periods to avoid over-saturation.

What you need to do / Task

Implement the maxTotalRevenue function that calculates the maximum possible total revenue an Airbnb host can achieve over N days, given the daily standard and premium revenues, and a constraint on setting premium prices.

Input & output

Function Signature (TypeScript):

function maxTotalRevenue(standardRevenues: number[], premiumRevenues: number[], K: number): number

Parameters:

  • standardRevenues: An array of integers, where standardRevenues[i] represents the revenue generated if a standard price is set for day i. The array length is N.
  • premiumRevenues: An array of integers, where premiumRevenues[i] represents the revenue generated if a premium price is set for day i. The array length is N.
  • K: An integer representing the minimum number of consecutive standard-priced days that must follow a premium-priced day before another premium-priced day can be set. Specifically, if a premium price is set on day i, then days i+1, i+2, ..., i+K must be set to standard prices (or be beyond the N-day period). The next earliest day a premium price can be set is i+K+1.

Return Value:

  • A single integer representing the maximum total revenue achievable over N days.

Clarifications

  • The days are 0-indexed, from 0 to N-1.
  • N is the length of standardRevenues (and premiumRevenues).
  • Revenues can be positive, zero, or negative (representing potential losses or costs).
  • If K=0, there's no cooldown period, meaning premium pricing can be set on consecutive days.
  • If K is large such that i+K+1 exceeds N, it simply means no further premium bookings can be made after day i.

Examples

1

Example 1

Input:

standardRevenues = [10, 2, 8], premiumRevenues = [15, 10, 20], K = 1

Output:

37

Note:

N=3, K=1.

  • Day 0: Premium (15). (Total: 15). Next premium available on day 0+1+1 = day 2.
  • Day 1: Must be Standard (2). (Total: 15+2=17).
  • Day 2: Premium (20). (Total: 17+20=37). Path: Premium(0), Standard(1), Premium(2). Total revenue: 15 + 2 + 20 = 37.
2

Example 2

Input:

standardRevenues = [5, 5, 5, 5, 5], premiumRevenues = [20, 1, 1, 20, 1], K = 1

Output:

55

Note:

N=5, K=1.

  • Day 0: Premium (20). (Total: 20). Next premium available on day 2.
  • Day 1: Must be Standard (5). (Total: 20+5=25).
  • Day 2: Standard (5). (Total: 25+5=30). Next premium available on day 3 (since day 1 was standard, day 2 was standard).
  • Day 3: Premium (20). (Total: 30+20=50). Next premium available on day 5 (beyond N).
  • Day 4: Must be Standard (5). (Total: 50+5=55). Path: Premium(0), Standard(1), Standard(2), Premium(3), Standard(4). Total revenue: 20 + 5 + 5 + 20 + 5 = 55.
3

Example 3

Input:

standardRevenues = [1, 1, 1], premiumRevenues = [10, 10, 10], K = 0

Output:

30

Note:

N=3, K=0. No cooldown. Choosing premium every day is optimal.

  • Day 0: Premium (10).
  • Day 1: Premium (10).
  • Day 2: Premium (10). Total revenue: 10 + 10 + 10 = 30.

Constraints

Constraints & assumptions

  • 1 <= N <= 10^5
  • 0 <= K < N
  • -1000 <= standardRevenues[i], premiumRevenues[i] <= 1000
  • The total revenue can fit within a standard 64-bit integer type.

Out of scope

  • Complex market demand forecasting.
  • A/B testing or real-time pricing adjustments.
  • Handling multiple concurrent listings.

What interviewers evaluate

  • Correct application of 1D Dynamic Programming to model the problem.
  • Efficient handling of state transitions and lookbacks, especially for the K cooldown period.
  • Robustness in handling edge cases (e.g., small N, K=0, negative revenues, indices out of bounds).
  • Optimal time and space complexity for the given constraints.

Loading editor...