Skip to the code
+25 XP

#505 Largest Empty Square in a Layout

medium

A page builder shows the page as a grid of cells. layout is an array of strings where "." is a free cell and "#" is a cell already used by a component.

Write largestFreeSquare(layout) that returns the side length of the largest square block made only of free cells, so a new square widget can be dropped there. Return 0 if no cell is free.

Example 1

Input: layout = ["....","....","...#"]
Output: 3

The 3 by 3 block in the top-left corner is all free.

Example 2

Input: layout = ["##","##"]
Output: 0

No cell is free.

Constraints

  • 1 <= layout.length, layout[0].length <= 2000
  • Every row has the same length and contains only . and #.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).