For each potential cut position - which is at the edge of any brick, I am counting the number of brick edges for all rows. Note that we need to use hash map to only track potential (not all) cuts. If bricks are very wide, you'll get MLE if you store all cut positions.

```
int leastBricks(vector<vector<int>>& wall) {
unordered_map<int, int> edges;
auto min_bricks = wall.size();
for (auto row : wall)
for (auto i = 0, width = 0; i < row.size() - 1; ++i) // skip last brick
min_bricks = min(min_bricks, wall.size() - (++edges[width += row[i]]));
return min_bricks;
}
```