How would you like to learn today?
Visualize algorithms in real time, explore them step by step, or challenge yourself with a test.Choose a path to focus—or scroll down to preview all options.
Visualize the algorithm step-by-step with interactive animations in real time.
Read the full explanation, examples, and starter code at your own pace.
Drag and arrange the algorithm steps in the correct execution order.
🧠 Select Active to activate
Follow every state change, comparison, and transformation as the execution unfolds in real time.
📖 Select Passive to activate
In this problem, we are given a set of n jobs. Each job has the following parameters:
Determine the optimal sequence of jobs that maximizes the profit while ensuring that no two jobs are executed simultaneously and each job is completed within its deadline.
Sort the jobs in descending order based on their profits. This ensures that the most profitable jobs are considered first.
Find the maximum deadline among all jobs. This determines the number of time slots available.
slots: An array of size maxDeadline initialized with -1. This array tracks which job is assigned to each time slot.maxProfit: Initialize to 0 to track the maximum profit achieved.count: Initialize to 0 to count the number of jobs included in the optimal sequence.For each job in the sorted list:
maxProfit.After iterating through all jobs, return:
count: Total number of jobs included in the sequence.maxProfit: Maximum profit achieved.jobs = [ {id: 1, deadline: 2, profit: 100}, {id: 2, deadline: 1, profit: 19}, {id: 3, deadline: 2, profit: 27}, {id: 4, deadline: 1, profit: 25}, {id: 5, deadline: 3, profit: 15} ]
[ {id: 1, profit: 100}, {id: 4, profit: 25}, {id: 3, profit: 27}, {id: 2, profit: 19}, {id: 5, profit: 15} ]3count = 3 (Jobs 1, 3, and 5)
maxProfit = 142
Input:
jobs = [ {id: 1, deadline: 2, profit: 50}, {id: 2, deadline: 1, profit: 40}, {id: 3, deadline: 2, profit: 60}, {id: 4, deadline: 1, profit: 20} ]
Output:
count = 2 (Jobs 3 and 1)
maxProfit = 110
Input:
jobs = [ {id: 1, deadline: 1, profit: 10}, {id: 2, deadline: 2, profit: 20}, {id: 3, deadline: 3, profit: 30} ]
Output:
count = 3 (Jobs 3, 2, and 1)
maxProfit = 60
Input:
jobs = [ {id: 1, deadline: 3, profit: 20}, {id: 2, deadline: 3, profit: 15}, {id: 3, deadline: 1, profit: 10} ]
Output:
count = 2 (Jobs 1 and 3)
maxProfit = 30
1 <= n <= 10001 <= profit[i], deadline[i] <= 10^4d is the maximum deadline)🎯 Select Challenge to activate
Drag and arrange the algorithm steps in the correct execution order instead of spending time typing code letter by letter.
The algorithm is divided into three logical parts. Carefully rearrange each section in the correct order to form a complete and valid solution.
Understand Below AlgorithmGreen text means the instruction is placed in the correct position.
Red text means the instruction is in the wrong position.
Instructions with the same background color indicate particular blocks start and end.
A tick mark means the instruction is correct and locked.
🔒 Locked steps cannot be moved. Only unlocked steps are draggable.
🔊 Enable sound for swap feedback and completion effects.