Top Amazon Questions | Level up your coding skills and quickly land a job

12 Live
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. Example The number of chapters is n = 3, the number of chapters read in a day is k = 2, the number of pages read from each chapter is p = 2, and the page counts of each chapter are pages = [3, 1, 4]. The chapters can be read as follows: Chapters read must be contiguous. - 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. 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 Returns long_int: the minimum number of days to read all pages of all chapters Constraints - 1 ≀ n ≀ 10^5 - 1 ≀ pages[i] ≀ 10^9 - 1 ≀ k ≀ n - 1 ≀ p ≀ 10^9 Input Format For Custom Testing Sample Case 0 Sample Input For Custom Testing STDIN 2 FUNCTION 3 4 1 2 pages[] size n = 2 pages = [3, 4] k = 1 p = 2 Sample Output 4 Explanation Read the first chapter for the first two days, and the second chapter for the next two days. Sample Case 1 Sample Input For Custom Testing STDIN FUNCTION 3 5 pages[] size n = 3 pages = [5, 1, 2] 1 2 3 3 k = 3 p = 3 Sample Output 2 Explanation After 1st day, the number of pages remaining = [2, 0, 0]. After 2nd day, the number of pages remaining = [0, 0, 0].

Asked in: AMAZON

Image of the Question

Question Image Question Image Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |