Calendar Availability for at Least P People
Problem statement
A binary matrix available has one row per person and one column per day. available[i][d] = 1 when person i is available on day d, and 0 otherwise.
Given p and x, return every starting day of an x-day consecutive period during which at least p people are available on every day of the period. A person's availability need not be shared with the same other people; only the daily count matters.
Return start indices in increasing order.
Function
availablePeriods(available: int[][], p: int, x: int) → int[]Examples
Example 1
available = [[1,1,0,1],[1,1,1,1],[0,1,1,1]]p = 2x = 2return = [0,1,2]Daily counts are [2,3,2,3], so every length-two period starting at 0, 1, or 2 meets the threshold.
Example 2
available = [[1,0],[1,1]]p = 2x = 1return = [0]Only day 0 has both people available.
Example 3
available = []p = 0x = 1return = []With no people, the calendar has no represented days.
Constraints
0 <= people <= 2000.- All rows have the same day count and
people * days <= 2,000,000. 0 <= p <= peopleand1 <= x.