2-D Dynamic Programming Bitmask DP
599. Minimum Number of Work Sessions to Finish the Tasks
You have n tasks, and task i takes tasks[i] units of time. You work in sessions. One session lasts
at most sessionTime units, and you take a break between sessions.
A task cannot be split: once you start it, you finish it in the same session. You may do the tasks in any
order, and a session may hold any number of tasks, as long as their times add up to at most sessionTime.
Return the smallest number of sessions needed to finish every task.
Example 1
Input: tasks = [3, 8, 2, 5, 4, 6], sessionTime = 10
3Explanation: One way is the sessions [8, 2], [6, 4] and [3, 5]. Two sessions are not enough: they hold at most
20 units, and the tasks add up to 28.
Example 2
Input: tasks = [9, 9, 9], sessionTime = 9
3Explanation: Each task fills a whole session, so every task needs a session of its own.
Example 3
Input: tasks = [1, 2, 3, 4], sessionTime = 1000000000
1Explanation: All four tasks fit in one session.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
n = tasks.length1 ≤ n ≤ 181 ≤ sessionTime ≤ 1091 ≤ tasks[i] ≤ sessionTime
Clarifying questions
What you would ask an interviewer before writing any code.