Minimum Boards to Cover Roof Holes
Updated
Problem statement
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 nboard covers every cell in one chosen row. - A vertical
m x 1board 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[][]) → intExamples
Example 1
roof = [[1,0,1],[0,1,0]]return = 2Cover row 1 and column 1. Together they cover all three holes.
Example 2
roof = [[1,1],[1,1]]return = 0An intact roof needs no board.
Example 3
roof = [[0,0,0],[0,0,0]]return = 2Two horizontal boards cover the complete roof, which is fewer than the three vertical boards.
Constraints
1 <= m, n <= 300.- Every row has exactly
ncells. - Every cell is
0or1.
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