Ctrl K

Slowest Reading Pace

Medium
A student has hours hours left before an exam and must read every chapter of the notes: chapter i has chapters[i] pages. They pick a fixed pace, a whole number of pages per hour. Each hour they work on one chapter: if at least that many pages are left in it, they read exactly that many; if fewer are left, they finish the chapter and rest for the remainder of the hour. They cannot start another chapter within the same hour. The student wants to read as slowly as possible and still get through everything. Return the minimum pace that lets them finish within hours hours.
Example 1
chapters=[12, 5, 9], hours=6 → 5

At 5 pages per hour: 12 pages take 3 hours, 5 take 1, 9 take 2, for 6 in total. At 4 per hour it would be 3 + 2 + 3 = 8 hours, which is too many.

Example 2
chapters=[20, 7], hours=2 → 20

There are as many hours as chapters, so each one must take a single hour: the pace must be at least the longest chapter.

Example 3
chapters=[3, 3, 3], hours=100 → 1
Constraints
  • 1 ≤ len(chapters) ≤ 10⁴
  • len(chapters) ≤ hours ≤ 10⁹
  • 1 ≤ chapters[i] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsFind in a Shifted Sorted Array MediumFirst and Last Copy MediumFind in a Row-Chained Grid MediumFind in a Shifted Array With Repeats MediumMinimum of a Shifted List Medium
loading Python…
Input
chapters=[12, 5, 9], hours=6
Expected
5

Run checks the first 3 tests in your browser. Submit checks all 103 tests on the server, hidden ones included.