Largest Rectangular Block of Free Seats in a Venue Map

Last updated: November 29, 2026

Quick Overview

Given a binary grid where 1 marks a free seat and 0 a taken seat, return the area of the largest axis-aligned rectangle consisting entirely of free seats.

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

0

0

0 solved


Given a binary grid where 1 marks a free seat and 0 a taken seat, return the area of the largest axis-aligned rectangle consisting entirely of free seats.

Framed around group bookings in an event-ticketing feature, this is maximal rectangle, which Google uses to test whether candidates can reduce a 2D problem to a known 1D one. The interviewer expects the histogram reduction and a correct monotonic stack for the largest rectangle in a histogram.

What the Interviewer Expects
  • Reduces each row to a histogram of consecutive free seats above
  • Solves largest rectangle in a histogram with a monotonic stack
  • Uses a sentinel to flush the stack at the end of each row
  • Achieves O(R * C) total time
  • Explains the width computation when popping
Key Topics to Cover
Monotonic Stack
Dynamic Programming
Matrix
Histogram
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
  • Return the coordinates of the rectangle, not just the area.
  • Find the largest square instead; is there a simpler DP?
  • Seats are booked and released online; how would you support updates?
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: list of equal-length strings of '0' and '1' (or a 2D array).
  • Output: max area of an all-1 axis-aligned rectangle; 0 if none....
High-Level Design

Process rows top to bottom keeping h[c], the number of consecutive 1s ending at the current row in column c (reset to 0 on a 0). Every all-1 rectangle has some bottom row, and on that row it is a re...


Submit Your Answer
Markdown supported