All problems
0640MediumArrayHash Table

Cable Drop Through The Panel Partition

Tracked in this browser only
Write code

Trains the technique from

LeetCode 554Brick Wall

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

An office partition is described by wall, listed from the top row downwards. Row i is the list of panel widths in that row, read from the left edge to the right edge, and every row spans the same total width.

A cable is dropped straight down the partition, from the top of the top row to the bottom of the bottom row, at one position strictly inside the partition: the two outer edges are not allowed. In each row the cable either slips down the seam where two neighbouring panels meet, touching neither of them, or it passes through the body of one panel. Return the smallest number of panels a single cable can pass through.

Examples

Example 1

Input
wall = [[4, 4], [2, 6], [2, 6], [3, 5]]
Output
2

Every row is 8 wide. A cable dropped 2 from the left edge slips down the seam of row 1 and the seam of row 2, and passes through a panel in row 0 and in row 3, giving 2 panels.

Example 2

Input
wall = [[1, 1, 1], [3], [1, 2]]
Output
1

Every row is 3 wide. A cable dropped 1 from the left edge slips down a seam in row 0 and a seam in row 2, and passes through the single panel of row 1, giving 1 panel.

Example 3

Input
wall = [[6], [6], [6]]
Output
3

Each row holds one panel 6 wide and has no seam, and the cable is not allowed on either outer edge, so it passes through a panel in all 3 rows.

Constraints

  • n == wall.length
  • 1 <= n <= 10^4
  • 1 <= wall[i].length <= 10^4
  • 1 <= sum of all wall[i].length <= 2 * 10^4
  • Every row of wall has the same total width.
  • 1 <= wall[i][j] <= 2^31 - 1

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def least_bricks(wall: list[list[int]]) -> int:
Java
public int leastBricks(List<List<Integer>> wall)
September 7
Apply