• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
May 26, 2024 |570 Views

PROBLEM OF THE DAY : 25/05/2024 | You and your books

Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Nitin Kaplas. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Dynamic Programming but also build up problem-solving skills.

In this problem, You have n stacks of books. Each stack of books has some nonzero height arr[i] equal to the number of books on that stack ( considering all the books are identical and each book has a height of 1 unit ). In one move, you can select any number of consecutive stacks of books such that the height of each selected stack of books arr[i] <= k. Once such a sequence of stacks is chosen, You can collect any number of books from the chosen sequence of stacks.
What is the maximum number of books that you can collect this way?

Example 1

Input
8 1
3 2 2 3 1 1 1 3

Output
3

Explanation 
We can collect maximum books from consecutive stacks numbered 5, 6, and 7 having height less than equal to K.

Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems-preview/you-and-your-books/1