Calendar Availability for at Least P People
Updated
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. The available people may differ from day to day. Only the number available on each day 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.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Minimum Swaps to Group Ones in a SquareAmazon · PHONE SCREEN
- Centered K-by-K Submatrix SumsCitadel · ONSITE INTERVIEW
- Restaurant Delivery HeatmapDoorDash · ONSITE INTERVIEW
- Alien Defense Turret PlacementBloomberg LP · ONSITE INTERVIEW
- Matrix Region SumRippling · OA · ONSITE INTERVIEW
- Subarray with a Given SumExpedia · ONSITE INTERVIEW
- Valid Max PoolingNVIDIA · ONSITE INTERVIEW
- Shortest Subarray with Sum at Least KOracle · ONSITE INTERVIEW
- Prefix Matrix Products and AutogradOpenAI · PHONE SCREEN · ONSITE INTERVIEW
- Number of Submatrices That Sum to TargetWhatNot · ONSITE INTERVIEW