#554
Brick Wall
specialist · 780 · lc medium +31 · verified · 56% accepted · 2,667 likes · top 50%
Description
A rectangular brick wall has n rows of unit-height bricks with possibly varying widths; every row spans the same total width. Draw a vertical line top-to-bottom that crosses as few whole bricks as possible. Passing through a brick edge counts as not crossing it, and the line may not run along the wall's outer edges. Given the 2D array wall describing each row, return the fewest bricks the line must cross.
Example 1:
Input: wall = [[1,2,2,1],[3,1,2],[1,3,2],[2,4],[3,1,2],[1,3,1,1]]
Output: 2
Example 2:
Input: wall = [[1],[1],[1]]
Output: 3
Code
1
2
3