Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Most Profit Assigning Work
Bookmark
Brute Force
Binary Search
Two Pointers
Input
Example 1
Example 2
Decreasing profit
Single job
Custom
difficulty
=
[2, 4, 6, 8, 10]
,
profit
=
[10, 20, 30, 40, 50]
,
worker
=
[4, 5, 6, 7]
jobs
diff / +profit
workers
ability
0
1
2
3
4
2
+10
4
+20
6
+30
8
+40
10
+50
4
5
6
7
jobs
diff / +profit
workers
ability
0
1
2
3
4
2
+10
4
+20
6
+30
8
+40
10
+50
4
5
6
7
totalProfit =
0
jobs
diff / +profit
workers
ability
0
1
2
3
4
2
+10
4
+20
6
+30
8
+40
10
+50
4
5
6
7
i
w
+10
>
0
→ bestProfit =
10
totalProfit =
0
jobs
diff / +profit
workers
ability
0
1
2
3
4
2
+10
4
+20
6
+30
8
+40
10
+50
4
5
6
7
i
w
difficulty
10
> ability
4
→ out of reach
totalProfit =
20
jobs
diff / +profit
workers
ability
0
1
2
3
4
2
+10
4
+20
6
+30
8
+40
10
+50
4
+20
5
6
7
i
w
+10
>
0
→ bestProfit =
10
totalProfit =
20
jobs
diff / +profit
workers
ability
0
1
2
3
4
2
+10
4
+20
6
+30
8
+40
10
+50
4
+20
5
6
7
i
w
difficulty
8
> ability
5
→ out of reach
totalProfit =
40
jobs
diff / +profit
workers
ability
0
1
2
3
4
2
+10
4
+20
6
+30
8
+40
10
+50
4
+20
5
+20
6
7
i
w
+10
>
0
→ bestProfit =
10
totalProfit =
40
jobs
diff / +profit
workers
ability
0
1
2
3
4
2
+10
4
+20
6
+30
8
+40
10
+50
4
+20
5
+20
6
7
i
w
difficulty
8
> ability
6
→ out of reach
totalProfit =
70
jobs
diff / +profit
workers
ability
0
1
2
3
4
2
+10
4
+20
6
+30
8
+40
10
+50
4
+20
5
+20
6
+30
7
i
w
ability
7
→ rescan every job, bestProfit = 0
totalProfit =
70
jobs
diff / +profit
workers
ability
0
1
2
3
4
2
+10
4
+20
6
+30
8
+40
10
+50
4
+20
5
+20
6
+30
7
i
w
difficulty
8
> ability
7
→ out of reach
totalProfit =
100
jobs
diff / +profit
workers
ability
0
1
2
3
4
2
+10
4
+20
6
+30
8
+40
10
+50
4
+20
5
+20
6
+30
7
+30
Total profit =
100
algo
master
.
io
Step:
Start: Give every worker the most profitable job they can handle
0 / 30
Input
Example 1
Example 2
Decreasing profit
Single job
Custom
difficulty
=
[2, 4, 6, 8, 10]
,
profit
=
[10, 20, 30, 40, 50]
,
worker
=
[4, 5, 6, 7]
0 / 30
algo
master
.
io
Step:
Start: Give every worker the most profitable job they can handle