FastPrepLargest Square Under Building Heights
Problems/Largest Square Under Building Heights

Largest Square Under Building Heights

Roblox logoRoblox● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Roblox new grad onsite interview. The report mentions finding a maximum square from building heights in a grid, without the geometry details. This version treats heights as skyline columns of width one and returns the side length of the largest square that fits inside. Our version is about 65% the same as the reported question.

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[]) → int

Examples

Example 1

heights = [3,3,3,1]return = 3

The first three columns contain a 3-by-3 square.

Example 2

heights = [5,1,5]return = 1

A tall single column has width 1, and the middle height prevents a larger square.

Example 3

heights = []return = 0

No 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

Interview reports that mention this question

  • Roblox New Grad Coding Rounds: 23 Experiences (Part 2 of 7)

Roblox interview experiences

  • Roblox OA: What It Tests (2026)
  • Roblox New Grad Early OA Tasks: 10 Experiences (Part 7 of 7)
  • Roblox New Grad Engineer Rounds: 13 Experiences (Part 6 of 7)
  • Roblox New Grad HackerRank OA: 18 Experiences (Part 5 of 7)
  • Roblox New Grad CodeSignal Finals: 23 Experiences (Part 4 of 7)
All Roblox interview questionsSee Roblox hiring insights
Saved
class Solution {
    public int largestBuildingSquare(int[] heights) {
        // write your code here
    }

}
Checking account…