Largest Square Under Building Heights
Updated
Problem statement
You are given nonnegative building heights in heights.
For this exercise, assume the buildings are adjacent unit-width columns on a grid, all starting at the same baseline. The filled cells below each height form a skyline. Find the largest square that fits entirely inside this filled region, with sides along the grid lines.
A square of integer side length s fits if there are at least s consecutive columns whose heights are all at least s. Return the maximum possible side length, not its area. Return 0 for an empty skyline or when all columns have height zero.
Function
largestBuildingSquare(heights: int[]) → intExamples
Example 1
heights = [3,3,3,1]return = 3The first three columns contain a 3-by-3 square.
Example 2
heights = [5,1,5]return = 1A tall single column has width 1, and the middle height prevents a larger square.
Example 3
heights = []return = 0No columns means no positive-size square.
Constraints
0 <= heights.length <= 1000.0 <= heights[i] <= 10^9.
More Roblox Onsite Interview questions
- Most Frequent Call Path From Function Trace LogsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Topological Sort with Secondary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Most Frequent Call Stack Per ThreadPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Count and Score Distinct Hat AssignmentsONSITE INTERVIEW · Seen Sep 2026
- Rate Limiter Sliding Window With Per-Entity LimitsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Most Frequent Call Path in Interleaved LogsONSITE INTERVIEW · Seen Aug 2026
- Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
- Maximize Distance to Closest Person — Return the SeatONSITE INTERVIEW · Seen Jun 2026
Similar questions at other companies
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Flatten a Mixed JSON ListNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
- Fountain SafetyGoogle · ONSITE INTERVIEWGoogle interview questions
- Trace Events from Stable Whole-Stack StatesAnthropic · ONSITE INTERVIEWAnthropic interview questions
- Next Smaller Ticket PriceAmazon · ONSITE INTERVIEW
- Next Greater Element to the RightTekion · ONSITE INTERVIEWTekion interview questions
- Surviving Balls after Directional CollisionsSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Daily TemperatureseBay · ONSITE INTERVIEWeBay interview questions
- Asteroid CollisionAdobe · ONSITE INTERVIEWAdobe interview questions
- Flatten a Nested ArrayFreshworks · ONSITE INTERVIEWFreshworks interview questions