Largest Rectangle of Free Slots in a Weekly Availability Grid

Last updated: November 29, 2026

Quick Overview

Rows are engineers on an on-call rotation and columns are hour slots; 1 means free. Return the area of the largest axis-aligned rectangle of all-free cells, representing the biggest block of people free together for a contiguous time range.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Rows are engineers on an on-call rotation and columns are hour slots; 1 means free. Return the area of the largest axis-aligned rectangle of all-free cells, representing the biggest block of people free together for a contiguous time range.

A Meta onsite hard question that builds on the histogram stack technique. The interviewer checks whether you reduce the 2D problem to one histogram per row and implement the monotonic stack without off-by-one errors.

What the Interviewer Expects
  • Convert each row into column heights of consecutive ones
  • Solve largest rectangle in a histogram with a monotonic stack
  • Explain why each bar is pushed and popped once
  • Combine for O(r * c) overall
  • Handle empty input and all-zero rows
Key Topics to Cover
Maximal rectangle
Monotonic stack
Histogram reduction
2D dynamic programming
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
  • Why does the stack approach find the widest span for each bar?
  • How would you return the rectangle's coordinates as well?
  • Can you solve it with left/right/height DP arrays instead of a stack?
  • What if rows can be reordered, so people need not be adjacent?
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 is an r x c matrix of 0s and 1s. Return the largest area of a rectangle containing only 1s. Rows and columns are contiguous; the interviewer confirms rows keep their fixed order. Matrix may be...

High-Level Design

Treat each row as the floor of a histogram. heights[j] counts consecutive 1s ending at the current row in column j, resetting to 0 on a 0. Any all-ones rectangle has a bottom row, and in that row'...


Submit Your Answer
Markdown supported