FastPrepFastPrep
Problem Brief

Find Minimum Days

FULLTIMEOA
See Amazon online assessment and hiring insights

A student is preparing for a scholarship test which is organized on the Amazon Academy platform and scheduled for next month.

There are n chapters to be studied where the ith chapter has pages[i] pages. In one day, the student decides to read up to p of the remaining pages, each from some k consecutive chapters. Thus, the number of pages remaining to be read is reduced by p from each of these chapters. If a chapter has less than p pages remaining, the student reads the remaining pages, and the remaining page count is set to 0 for subsequent days. Find the minimum number of days the student needs to read all the chapters completely, i.e., the remaining page count of all chapters is 0.

Note: The chapters read must be contiguous.

Function Description

Complete the function findMinimumDays in the editor below.

findMinimumDays has the following parameters:

  • int pages[n]: the number of pages in each chapter
  • int k: the number of chapters chosen each day
  • int p: the maximum number of pages read from each chapter in a day

Returns

long int: the minimum number of days to read all pages of all chapters

🌷 Endless thanks to a super important old friend who has always been there to help! πŸ’œπŸ™

1Example 1

Input
pages = [3, 1, 4], k = 2, p = 2
Output
4
Explanation
Example 1 illustration
The chapters can be read as follows:
  • Choose chapters 1 and 2, remaining pages to be read = [1, 0, 4]
  • Choose chapters 1 and 2, remaining pages to be read = [0, 0, 4]
  • Choose chapters 2 and 3, remaining pages to be read = [0, 0, 2]
  • Finally, choose chapters 2 and 3, remaining pages to be read = [0, 0, 0]
The chapters cannot be read in less than 4 days.

2Example 2

Input
pages = [3, 4], k = 1, p = 2
Output
4
Explanation
Let's trace this sample case: Day 1: Choose chapter 1 (pages = 3). Read min(3,2)=2 pages. Remaining pages: [3βˆ’2,4]=[1,4]. Day 2: Choose chapter 1 (pages = 1). Read min(1,2)=1 page. Remaining pages: [1βˆ’1,4]=[0,4]. Day 3: Choose chapter 2 (pages = 4). Read min(4,2)=2 pages. Remaining pages: [0,4βˆ’2]=[0,2]. Day 4: Choose chapter 2 (pages = 2). Read min(2,2)=2 pages. Remaining pages: [0,2βˆ’2]=[0,0]. So, for this sample case, the minimum number of days would be 4. This test case is fromt the second source we found. You can find source ss from the second source images in the Problem Source section below.

Constraints

Limits and guarantees your solution can rely on.

  • 1 ≀ n ≀ 10^5
  • 1 ≀ pages[i] ≀ 10^9
  • 1 ≀ k ≀ n
  • 1 ≀ p ≀ 10^9
public long findMinimumDays(int[] pages, int k, int p) {
  // write your code here
}
Input

pages

[3, 1, 4]

k

2

p

2

Output

4

Sign in to submit your solution.