16. Minimum Number of Workers
β GFG solution to the Minimum Number of Workers problem using greedy interval coverage. Efficiently determine the minimum workers needed to cover the entire day. π
π§© Problem Description
π Examples
Example 1
Input: arr[] = [1, 2, 1, 0]
Output: 1
Explanation: The person at index 1 can cover the interval [-1, 3]. After adjusting to valid
bounds, this becomes [0, 3], which fully covers the entire working day 0 to n-1. Therefore,
only 1 person is required to cover the whole day.Example 2
Input: arr[] = [2, 3, 4, -1, 2, 0, 0, -1, 0]
Output: -1
Explanation: Persons up to index 2 cover interval [0β¦6], but working hour 7 cannot be covered
as arr[7] = -1. Since the 7th hour cannot be covered by any person, it is impossible to cover
the full working day.Example 3
π Constraints
β
My Approach
Greedy Interval Selection
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated