Medium
Quiz
#554 Brick Wall
APPROACH
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
1 of 4
1:00
What is the optimal approach for this problem?