Minimum daily reading pace to finish a textbook
I was asked this
No reports yet. Sign in to say where you were asked it.
A student must read a textbook of n chapters before an exam. Chapter i has pages[i] pages, and the chapters must be read in order.
The student picks a daily limit x. On each day they read from the current chapter until either the chapter ends or they have read x pages, whichever comes first. A day never continues into the next chapter: if a chapter ends partway through the day, the student stops for that day.
Given pages and the number of days days left before the exam, return the smallest positive integer x that lets the student finish every chapter within days days. Return -1 if no x works.
Implement:
def min_pages_per_day(pages: list[int], days: int) -> int: ...
Constraints
1 <= n <= 10^51 <= pages[i] <= 10^91 <= days <= 10^9
Example 1
pages = [7, 2, 6], days = 6
output: 3
With x = 3 the student needs 3 + 1 + 2 = 6 days. With x = 2 they need 4 + 1 + 3 = 8 days, which is too many.
Example 2
pages = [4, 9], days = 1
output: -1
Each chapter takes at least one day, so two chapters cannot fit in one day.
Reconstructed from the reported question; details may differ from what interviewers ask.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
What the labs asked this week
A weekly email of what OpenAI, Anthropic and the other top AI labs asked engineers, round by round.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
Sign in to submit your code; every attempt is kept here.
