FastPrepMinimum Boards to Cover Roof Holes
Problems/Minimum Boards to Cover Roof Holes

Minimum Boards to Cover Roof Holes

Google logoGoogle● HardNEW GRADINTERNPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives an m by n binary roof where zero cells are holes. You may use full-row boards of 1 by n and full-column boards of m by 1, and you want the fewest boards. Comments point to bipartite matching and Kőnig's theorem on minimum vertex cover. We chose the wording for board direction, the signature, the examples, and the input limits. Our version is about 94% the same as the reported question.

Special thanks: 🌷 A special thank you to a lovely, amazing fren who shared that this question appeared again on November 12, 2026! ( ˶ˆᗜˆ˵ ) 💜

An m x n binary matrix roof describes a roof. A cell containing 0 is a hole, while a cell containing 1 is intact.

You may place either kind of board:

  • A horizontal 1 x n board covers every cell in one chosen row.
  • A vertical m x 1 board covers every cell in one chosen column.

Boards may overlap. Return the minimum number of boards needed so every hole is covered.

Function

minimumRoofBoards(roof: int[][]) → int

Examples

Example 1

roof = [[1,0,1],[0,1,0]]return = 2

Cover row 1 and column 1. Together they cover all three holes.

Example 2

roof = [[1,1],[1,1]]return = 0

An intact roof needs no board.

Example 3

roof = [[0,0,0],[0,0,0]]return = 2

Two horizontal boards cover the complete roof, which is fewer than the three vertical boards.

Constraints

  • 1 <= m, n <= 300.
  • Every row has exactly n cells.
  • Every cell is 0 or 1.

More Google Phone Screen questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Longest Decreasing Matrix Path with Limited RelaxationsDuolingo · ONSITE INTERVIEW
  • Making a Large IslandMeta · ONSITE INTERVIEW
  • Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Count Groups of Diseased PlantsYellow.ai · PHONE SCREEN
  • Island Count and Maximum AreaOracle · ONSITE INTERVIEW
  • Count Connected IslandsUber · PHONE SCREEN
  • Island Area and Water BoundaryWaymo · PHONE SCREEN
  • Number of IslandsSpaceX · PHONE SCREEN
  • Count Islands in a Binary GridApple · PHONE SCREEN
  • Number of IslandsTripjack · ONSITE INTERVIEW

Interview reports that mention this question

  • Google New Grad R2 Roof Boards and Prefix Conflicts: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
See Google hiring insights
Saved
class Solution {
    public int minimumRoofBoards(int[][] roof) {
        // write your code here
    }
}
Checking account…