![]() |
VOOZH | about |
Geeks for Geeks is organizing a hackathon consisting of N sections, each containing K questions. The duration of the hackathon is H hours.
Each participant can determine their speed of solving questions, denoted as S (S = questions-per-hour). During each hour, a participant can choose a section and solve S problems. If a section has fewer than S questions, the participant will not solve any additional questions from that section during that hour.
The goal is for the participant to solve the questions at a slower pace while still completing all the questions before the hackathon ends, the task is to find the S such that ensures the participant will solve all the questions within H hours.
Examples:
Input: section = [ 2, 4, 2, 4, 5], H = 8
Output: 3
Explanation: Participate will solve 3 questions per hour to solve all the questions within 8 hours.Input: section = [ 8, 11, 18, 20], H = 10
Output: 7
Explanation: Participate will solve 7 questions per hour to solve all the questions within 10 hours.
Naïve Approach: The basic way to solve the problem is as follows:
H is equal to the number of sections.H.max_element.k_min to k_max.H, return the current speed k.Below is the implementation of the above approach:
Minimum eating speed required: 7
Time Complexity: O(n (max K −min K))
Auxiliary Space: O(1)
Efficient Approach: To solve the problem follow the below idea:
We can solve this problem using Binary Search
Follow the below steps to solve the problem:
Below is the implementation of the above approach:
7
Time Complexity: O(n.logn)
Auxiliary Space: O(1)