Maximum Cells
Learn this problemProblem statement
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 '#' 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.
Function
maximumCells(A: String[]) → intExamples
Example 1
A = [".##..", ".#.#.", ".....", "##..#"]return = 7
Example 2
A = ["#.#", "...", "#.#"]return = 4
Example 3
A = ["###..", ".....", "###.#"]return = 7
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 '#'More Microsoft problems
- Maximum Pipeline ThroughputOA · Seen Jul 2026
- Maximum Strong Team SubarrayOA · Seen Jul 2026
- Minimum Cost K-Capable ModelsOA · Seen Jul 2026
- Alphabetically Smallest PalindromeOA · Seen Jul 2026
- Maximum Reward PointsOA · Seen Jul 2026
- Maximum Strength of Every NeuronOA · Seen Jul 2026
- Neural Network Subnetwork StrengthOA · Seen Jul 2026
- XOR MultiplicationOA · Seen Jul 2026