Maximum Cells

Problem Overview

  • Select at most two narrow rectangles (1-cell wide column or 1-cell high row) of '.' cells to maximize total cultivated cells.
  • Input: array A of N strings forming an N×M grid with '.' (land) and '#' (building); Output: integer max cells.
  • Constraints: 1 ≤ N,M ≤ 500; all rows have the same length.
  • Real-world context: plan rice cultivation areas on a village map while avoiding buildings.
  • From Microsoft interviews; a classic coding interview interview question problem.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: