561. Minimum Number of Work Sessions to Finish the Tasks

HardBinary SearchDPBitmask

Given task durations and a session length sessionTime (each task duration is at most sessionTime), you complete tasks in work sessions where the total time within a session cannot exceed sessionTime; a task must be finished within one session. Return the minimum number of sessions needed to finish all tasks. The input is JSON {tasks, sessionTime}.

Input: JSON {tasks, sessionTime}.

Output: Integer — the minimum number of sessions.

Examples

Example 1
Input: {"tasks":[1,2,3],"sessionTime":3}
Output: 2
Explanation: Sessions [1,2] and [3].
Example 2
Input: {"tasks":[3,1,3,1,1],"sessionTime":8}
Output: 2
Explanation: Two sessions suffice.
Example 3
Input: {"tasks":[1],"sessionTime":5}
Output: 1
Explanation: One task, one session.

Constraints

Asked by

SwiggyAmazon
Solve this problem in the editor →