Tap here to switch tabs
Problem
Submissions

Problem: Filling Bookcase Shelves

Filling Bookcase Shelves arranges books in their given order across shelves with limited width. Return the minimum total height when each shelf’s height is set by its tallest book.

Statement

You are given an array books where books[i] = [thickness_i, height_i] represents the thickness and height of the book at index i. You are also given an integer shelfWidth.

Books must be arranged in order onto horizontal shelves. Each shelf can hold books with a total thickness of at most shelfWidth. When placing a book on a shelf, its height contributes to the shelf height, which is the maximum height among all books placed on that shelf. If placing the next book would exceed shelfWidth on the current shelf, or if you choose to start a new shelf, you can place it on a new shelf below the current one.

Return the minimum possible total height of the entire bookcase after placing all the books in the given order.

Constraints:

  • 1≤1 \le books.length ≤1000\le 1000

  • 1≤1 \le thickness_i ≤\le shelfWidth ≤1000\le 1000

  • 1≤1 \le height_i ≤1000\le 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Filling Bookcase Shelves

Filling Bookcase Shelves arranges books in their given order across shelves with limited width. Return the minimum total height when each shelf’s height is set by its tallest book.

Statement

You are given an array books where books[i] = [thickness_i, height_i] represents the thickness and height of the book at index i. You are also given an integer shelfWidth.

Books must be arranged in order onto horizontal shelves. Each shelf can hold books with a total thickness of at most shelfWidth. When placing a book on a shelf, its height contributes to the shelf height, which is the maximum height among all books placed on that shelf. If placing the next book would exceed shelfWidth on the current shelf, or if you choose to start a new shelf, you can place it on a new shelf below the current one.

Return the minimum possible total height of the entire bookcase after placing all the books in the given order.

Constraints:

  • 1≤1 \le books.length ≤1000\le 1000

  • 1≤1 \le thickness_i ≤\le shelfWidth ≤1000\le 1000

  • 1≤1 \le height_i ≤1000\le 1000