Days Until a Cheaper Night on a Listing's Price Calendar

Last updated: November 29, 2026

Quick Overview

Given a listing's nightly prices in date order, return for each night how many nights later a strictly cheaper night occurs, or 0 if none does. Guests use this kind of hint to decide whether waiting a few days saves money.

Airbnb
Coding & Algorithms
Software Engineer
Airbnb
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


Given a listing's nightly prices in date order, return for each night how many nights later a strictly cheaper night occurs, or 0 if none does. Guests use this kind of hint to decide whether waiting a few days saves money.

Airbnb's flexible date tools can nudge guests toward cheaper nearby dates. As an online assessment item it checks whether you recognize the next-smaller-element pattern and use a monotonic stack instead of a nested loop.

What the Interviewer Expects
  • Identify the brute force O(n^2) and why it is too slow for long calendars
  • Use a stack of indexes with non-decreasing prices
  • Resolve waiting nights when a cheaper price arrives
  • Handle equal prices correctly (strictly cheaper only)
Key Topics to Cover
monotonic stack
next smaller element
arrays
amortized analysis
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you return the cheaper price itself instead of the distance?
  • How would you limit the search to the next 14 nights?
  • How would you find the previous cheaper night instead?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: list of prices. Output: list of the same length where out[i] = j - i for the first j > i with prices[j] < prices[i], else 0....

High-Level Design

Scan left to right with a stack of indexes still waiting for a cheaper night. The stack's prices are non-decreasing from bottom to top, because any higher price below a lower one would already have be...


Submit Your Answer
Markdown supported

Related Questions