Description
Given a brick wall represented as a 2D array, find a vertical line that crosses the fewest bricks. Return the minimum bricks crossed.
Examples
Input:
wall = [[1,2,2,1],[3,1,2],[1,3,2],[2,4],[3,1,2],[1,3,1,1]]Output:
2Explanation:
Cross 2 bricks at position 4.
Input:
wall = [[1]]Output:
1Explanation:
Minimal case with a single-row, single-brick wall.
Input:
wall = [[2,1,1],[1,1,2],[1,3]]Output:
1Explanation:
The wall has width 4. At position 2, there are gaps in rows 0 and 2 (but not row 1), so crossing 1 brick. At position 3, there's a gap only in row 1, so crossing 2 bricks. Position 2 is optimal with only 1 brick crossed.
Constraints
- •
1 ≤ n ≤ 10⁴