Daily Temperatures
Real-world version: Nights Until a Fuller HouseThe statement here is our own: the same inputs, outputs and technique.
A repertory theatre keeps a run log: occupancy[i] is the percentage of seats sold on the i-th night of the run, in performance order.
The manager wants to know, for every night, how soon the house got fuller than it was that night. Build an array waits of the same length where waits[i] counts the nights between night i and the earliest night after it whose percentage is strictly above occupancy[i]. Nights that tie do not count as fuller. Put 0 in waits[i] when no later night in the run beats night i.
Examples
Example 1
- Input
- occupancy = [64, 71, 68, 68, 95, 84, 100]
- Output
- [1, 3, 2, 1, 2, 1, 0]
Night 1 already beats night 0, so the first entry is 1. Night 2 and night 3 both sold the same 68 percent, so night 2 has to skip past night 3 and wait for the 95 percent night.
Example 2
- Input
- occupancy = [88, 76, 55]
- Output
- [0, 0, 0]
The run only thins out, so no night is ever followed by a fuller one.
Example 3
- Input
- occupancy = [45, 45, 45]
- Output
- [0, 0, 0]
Every night sells the same share of the house, and an equal night is not a fuller night.
Constraints
- 1 <= occupancy.length <= 10^5
- 30 <= occupancy[i] <= 100
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def nights_until_fuller(occupancy: list[int]) -> list[int]:public int[] nightsUntilFuller(int[] occupancy)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Next Greater Element IReal-world version: Auction Watchlist HighsEasy
- Final Prices With a Special Discount in a ShopReal-world version: Job Hour CreditsEasy
- Next Greater Element IIReal-world version: Loop Trail Next RiseMedium
- Sum of Subarray MinimumsReal-world version: Weakest Reading Per StretchMedium