Tap here to switch tabs
Problem
Submissions

Problem: Filling Bookcase Shelves

med
30 min
Try to solve the Filling Bookcase Shelves problem.

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

med
30 min
Try to solve the Filling Bookcase Shelves problem.

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