Brick Wall

Problem Id: 554 Difficulty: Medium


Intuition

Solution


class Solution:
    def leastBricks(self, wall: List[List[int]]) -> int:
        no_bricks = defaultdict(int)
        for row in wall:
            i = 0
            for width in row[:-1]:
                i += width
                no_bricks[i] += 1
        vs = no_bricks.values()
        if not vs:
            return len(wall)
        return len(wall) - max(vs)