Find Minimum Pages Per Day
Learn this problemProblem statement
A student is preparing for a test from Amazon Academy for a scholarship.
The student is required to completely read n chapters (which is the length of the pages array) for the test, where the ith chapter has pages[i] number of pages. The chapters are read in increasing order of the index. Each day the student can either read till the end of a chapter or at most x pages, whichever is minimum. The number of pages remaining to read decreases by x in the latter case.
The test will be given in days number of days from now. Find the minimum number of pages, x, which the student should read each day to finish all pages of all chapters within days number of days. If it is not possible to finish these chapters in days number of days, return -1.
Note: In one day, the student cannot read pages of more than one chapter. Thus, if a chapter finishes, the next chapter starts only on the next day even if the number of pages read is less than x.
Function
findMinimumPagesPerDay(pages: int[], days: int) → intComplete the function findMinimumPagesPerDay in the editor.
findMinimumPagesPerDay has the following parameters:
int pages[n]: an array of integers representing the number of pages in each chapterint days: the number of days to finish reading
Returns
int: the minimum number of pages to read each day, or -1 if it is not possible.
Examples
Example 1
pages = [5, 3, 4]days = 4return = 4Example 2
pages = [2, 3, 4, 5]days = 5return = 4Example 3
pages = [2, 3, 4]days = 4return = 3
Constraints
nis the number of chapters, wherenequals the length ofpagesandn >= 1.pages[i] >= 1for every chapteri.days >= 1.- Each chapter requires at least one day to read (the next chapter starts only on a new day), so if
days < nthe answer is-1. - The answer
xsatisfies1 <= x <= max(pages); it is the smallestxsuch that the total days needed (summingceil(pages[i] / x)over all chapters) is at mostdays.
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026