> For the complete documentation index, see [llms.txt](https://chiragjain.gitbook.io/neetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chiragjain.gitbook.io/neetcode/554-brick-wall/code.md).

# CODE

```python
class Solution:
    def leastBricks(self, wall: List[List[int]]) -> int:
        # Init the dict with default values for the case where there is only
        # one brick in each row of the wall
        gap_count = {0: 0}
        for row in wall:
            gap = 0
            for brick in row[:-1]:
                gap += brick
                gap_count[gap] = 1 + gap_count.get(gap, 0)
        return len(wall) - max(gap_count.values())
                
            
            
            
        
        
```
