Skip to the code
cf.
+50 XP

#269 Largest Free Block on a Layout Grid

hard

A dashboard builder lays widgets on a grid. grid is an array of equal-length strings, one per row, where . is a free cell and # is taken by a widget.

Write largestFreeBlock(grid) that returns the area (number of cells) of the largest rectangle made only of free cells, with sides along the grid lines. Return 0 if no cell is free.

Example 1

Input: grid = ["#.#..","#.###","....#","#..#."]
Output: 4

Row 2 columns 0 to 3 are free: area 4. No bigger free rectangle exists.

Example 2

Input: grid = ["..",".."]
Output: 4

The whole 2 by 2 grid is free.

Constraints

  • 1 <= grid.length <= 200
  • 1 <= grid[0].length <= 200
  • Each row has only . and #.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

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