Skip to content

Practice Minimum Number of Work Sessions to Finish the Tasks

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1986
LeetCode Problem

Minimum Number of Work Sessions to Finish the Tasks

Problem Statement

Task i takes tasks[i] hours. A work session may contain at most sessionTime consecutive hours of work before a break. Every task must fit entirely within one session, tasks may be performed in any order, and another task may begin immediately after the previous one finishes. Return the fewest sessions needed to complete all tasks. Every individual task is guaranteed to take at most sessionTime hours.

Source: Minimum Number of Work Sessions to Finish the Tasks on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
tasks = [1,2,3], sessionTime = 3
Output
2

# Example 2

Input
tasks = [3,1,3,1,1], sessionTime = 8
Output
2

# Example 3

Input
tasks = [1,2,3,4,5], sessionTime = 15
Output
1

Constraints

n == tasks.length
1 <= n <= 14
1 <= tasks[i] <= 10
max(tasks[i]) <= sessionTime <= 15

Related LeetCode Problems

Practice more problems similar to Minimum Number of Work Sessions to Finish the Tasks.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.