1111. Fewest Work Sessions

A repair technician has a list of jobs, where tasks[i] is the number of minutes job i takes. She works in focused sessions of at most sessionTime minutes each; between two sessions she takes a long break, and a break is the only way to start fresh. Inside one session she can do any number of jobs back to back, as long as their total time does not exceed sessionTime.

A job must be finished inside a single session; it can not be paused and resumed after a break. The jobs may be done in any order. Return the smallest number of sessions that is enough to finish every job. You may assume that every single job fits in one session.

Example 1

Input:
tasks = [2,3,3,4,5], sessionTime = 7
Output:
3
Explanation:

The jobs fit into three sessions: 2 + 5, 3 + 4 and 3; their total of 17 minutes rules out two sessions of 7 minutes.

Example 2

Input:
tasks = [4,4,5,5], sessionTime = 9
Output:
2
Explanation:

Pairing each 4 with a 5 uses two full sessions of 9 minutes, whereas doing the jobs in the given order would need three.

Constraints

1 ≤ tasks.length ≤ 15

1 ≤ tasks[i] ≤ 10

tasks[i] ≤ sessionTime ≤ 20

How this problem is judged

Answers
Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Time per case
Python 1,600 msC++ 400 msJava 800 msJavaScript 800 msTypeScript 800 ms

Expected complexity

Time
O(2^n * n)
Space
O(2^n)

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…