2daysbeforeinterview
Home1Companies2Problems3Experiences4Compensation5Assistant

Spaces

Saved work

Your prep

Notes6Bookmarks7Submissions

Community

Leaderboard8Send feedback
Contribute9
2daysbeforeinterview
2daysbeforeinterview

Straight from the interview room.

Browse

  • Companies
  • Problems
  • Experiences
  • Compensation
  • Leaderboard
  • Pricing

Contribute

  • Add a question
  • Share an experience
  • Report compensation
  • Committed Contributor
  • Send feedback

About

  • About 2daysbeforeinterview
  • Contact
  • Privacy
  • Terms
  • Refunds
  • Delivery

© 2026 2daysbeforeinterview

  • Instagram(opens in a new tab)
  • YouTube(opens in a new tab)
  • X (Twitter)(opens in a new tab)
  • help@2daysbeforeinterview.com
HomeCompaniesProblems
Keep holding ⌥Alt and press a number · ? for every shortcut
Back to resultsFunction: All functionsEngineeringDataMachine learningProductDesignQuality assuranceBusiness
Home1Companies2Problems3Experiences4Compensation5Assistant

Spaces

Saved work

Your prep

Notes6Bookmarks7Submissions

Community

Leaderboard8Send feedback
Previous questionNext question

Your results

  • Licious
Results
Back to results
DSA
1 reportlast asked …
Licious

Scheduling Processors for Task Processing

You are given a queue of tasks, where tasks[i] is the time task i needs, and a deadline. Schedule the tasks on identical processors and return the minimum number of processors required so that every task is processed by deadline.

Processing rules:

  1. Every processor is free at time 0 and runs one task at a time, without interruption.
  2. Tasks are picked up in queue order. The next task always goes to the processor that becomes free earliest, and starts the moment it is free.
  3. Every task must finish at or before time deadline.

If no number of processors meets the deadline, return -1.

Example 1

Input:  tasks = [3,2,4,1,2], deadline = 6
Output: 2

One processor needs 12 time units. With two, the tasks finish at 3, 2, 6, 4 and 6: the processor running 3 then takes 1 and 2, the other runs 2 then 4.

Example 2

Input:  tasks = [3,3,2,2,2], deadline = 6
Output: 3

The work totals 12 = 2 × 6, but two processors are not enough here: the first two tasks finish at 3, the next two at 5, and the last task starts at 5 and ends at 7. Three processors finish everything by 5.

Example 3

Input:  tasks = [4,7,2], deadline = 6
Output: -1

The task of length 7 alone runs past 6, however many processors there are.

Constraints

  • 1 <= tasks.length <= 10^5
  • 1 <= tasks[i] <= 10^4
  • 1 <= deadline <= 10^9

Hints

0/3

Domains

Backend
asked Sept 2021Report
Discussion
Related questions
Asked atLicious
My notes
Practice
EditorialLocked
Community solutions
Learning resources(3)
Licious
Licious