Description
Solutions
Maximum Cells
🔥 FULLTIME

A map of village is split into a rectangular grid with N rows (numbered from 0 - N - 1) and M columns (numbered from 0 to M - 1). Establish at most two rice cultivation areas in the village, using only cells dedicated to this purpose.

The map is described by an array of strings: the C-th character of the R-th string can be either '.', meaning that the square of land in the R-th row and C-th column is a place where rice cultivation can be established, or '#' if it is an agricultural building.

The shape of the cultivation areas should be a narrow rectangle (vertical with one cell width or horizontal with one cell height).

What is the maximum number of cells that can be used for cultivation by choosing at most two areas?

Given an array of strings A, returns an integer: the maximum number of cells that can be used for cultivation by choosing at most two areas.

Example 1:

Input:  A = [".##..", ".#.#.", ".....", "##..#"]
Output: 7
Explanation:

Example 2:

Input:  A = ["#.#", "...", "#.#"]
Output: 4
Explanation:

Example 3:

Input:  A = ["###..", ".....", "###.#"]
Output: 7
Explanation:
Constraints:
  • N is an integer within the range [1..500]
  • all strings in A are of the same length M within the range [1..500]
  • all strings in A consist only of the characters '.' and/or '#'
Thumbnail 0
Testcase

Result
Case 1

input:

output: