Code RoomLargest free region
HardPrep Room Coding #4905

Largest free region

CodingAlgorithms & data structuresSenior–Staff~40 min

A data centre floor is a width by height rectangle of one metre cells, with x running from 0 to width-1 and y from 0 to height-1. Racks arrive as a list of four integer rows x1, y1, x2, y2, and a rack occupies every cell with x1 <= x <= x2 and y1 <= y <= y2. Footprints may overlap and always sit inside the floor. A trolley rolls between orthogonally adjacent free cells, so free cells that touch edge to edge belong to the same region. Return the number of cells in the largest connected region of free cells, or 0 when the floor has no free cell at all. width and height reach one million, so nothing that touches every cell can finish, but there are at most 200 racks.

Implement
floor_open_area(width: int, height: int, racks: list[list[int]]) → int
Examples
in[8,6,[[2,0,2,4],[5,2,6,5]]]out35
in[4,4,[]]out16
in[6,6,[[0,2,5,3],[2,0,3,5]]]out4
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 40 min
InputExpectedGot
[8,6,[[2,0,2,4],[5,2,6,5]]]35not run yetsample
[4,4,[]]16not run yetsample
[6,6,[[0,2,5,3],[2,0,3,5]]]4not run yetsample