Problem Submissions Solution

You and your books

Difficulty: Easy

Acceptance: %

Points: 20.00

You are given n stacks of books, where each stack arr[i] represents the number of books in that stack (with each book having a height of 1 unit). In a single move, you can choose any number of consecutive stacks such that the height of each selected stack is less than or equal to k. After selecting a sequence of stacks, you can collect any number of books from those chosen stacks.

Your task is to determine the maximum number of books you can collect in this manner.  You need to complete the function max_Books() which takes the integer arr, n, and k returns the maximum number of books you can collect.

Topics

Companies

Articles

Examples:

Expected Time Complexity: O(n)

Expected Space Complexity: O(1)

Constraints:
  • 1 <= n <= 10^5
  • 1 <= k <= 10^9
  • 0 <= arr[i] <= 10^9
Companies:
Visa Cisco
Topics:
Array Dynamic Programming
Locked Content
Access Restricted: Please Login to access the code editor and test cases.