Minimum Work Sessions to Finish All Tasks
A worker completes tasks of given durations in fixed-length sessions. A task cannot be split across sessions. Find the minimum number of sessions needed to finish everything.
Problem
Given an array tasks of task durations and an integer sessionTime where each session lasts sessionTime and each task must fit entirely within a single session (each task duration <= sessionTime), return the minimum number of sessions required to complete all tasks.
Input
An array tasks and an integer sessionTime.
Output
An integer: the minimum number of sessions.
Constraints
- 1 <= tasks.length <= 14
- 1 <= tasks[i] <= sessionTime <= 15
Examples
Example 1
Input
tasks = [1,2,3], sessionTime = 3
Output
2
Session 1: {1,2}; Session 2: {3}.
Example 2
Input
tasks = [3,1,3,1,1], sessionTime = 8
Output
1
All tasks total 9 > 8? No: 3+1+3+1+1 = 9 > 8, so 2... but grouping fits 1 session? Actually total is 9 so 2 sessions; with sessionTime 8 the answer is 2.