Skip to the code
cf.
+25 XP

#169 Earliest Day for Banner Slots

medium

A home page has a row of ad slots. Slot i becomes available on day readyDay[i] and stays available after that. A campaign needs blocks banners, and each banner covers size slots that are next to each other. Two banners can't share a slot.

Write earliestDay(readyDay, blocks, size) that returns the earliest day on which the campaign can be placed, or -1 if the row is too short for it.

Example 1

Input: readyDay = [1,10,3,10,2], blocks = 3, size = 1
Output: 3

On day 3, slots 0, 2, and 4 are free: three banners of size 1.

Example 2

Input: readyDay = [1,10,3,10,2], blocks = 3, size = 2
Output: -1

Three banners of size 2 need 6 slots, but there are only 5.

Constraints

  • 1 <= readyDay.length <= 100000
  • 1 <= readyDay[i] <= 10^9
  • 1 <= blocks, size <= 10^5
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).