Skip to the code
cf.
+50 XP

#171 Split a Feed Into Pages

hard

A print view must split a long feed into exactly pages pages. heights[i] is the height of post i in pixels. Posts stay in order, each page holds one or more posts next to each other, and a post can't be split across pages.

The tallest page decides how much the layout needs to scale, so it should be as short as possible. Write minTallestPage(heights, pages) that returns the smallest possible height of the tallest page.

Example 1

Input: heights = [7,2,5,10,8], pages = 2
Output: 18

Split as [7, 2, 5] and [10, 8]: the pages are 14 and 18 tall. No split does better.

Example 2

Input: heights = [1,2,3,4,5], pages = 2
Output: 9

[1, 2, 3] and [4, 5] give pages of 6 and 9.

Constraints

  • 1 <= pages <= heights.length <= 10000
  • 0 <= heights[i] <= 10^6
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).