Problem · Graph
Task Master (Also for Infra Automation Intern)
Learn this problemProblem statement
Eric is the most methodical employee at the Acme company. His manager assigned him a number of tasks for the quarter, and gave him a list of notes regarding the order they must be performed. Each note states that some task must be completed before some related task. If he goes to perform some task and sees that a rule exists requiring that this task be performed before an already completed task, then he cannot perform the task. Help Eric determine the maximum number of tasks he can complete.
Function
tasks(n: int, a: int[], b: int[]) → int
Complete the function tasks in the editor. It must return an integer denoting the maximum number of tasks that Eric can complete.
tasks has the following parameters(s):
int n: integer, number of tasksa[a[0],...a[n-1]]: an array of integers, the dependent tasksb[b[0],...b[n-1]]: an array of integers, the primary tasksExamples
Example 1
n = 7a = [1, 2, 3, 4, 6, 5]b = [7, 6, 4, 1, 2, 1]return = 6
For example, Eric has
n=7 tasks to complete. His manager gives him m=6 notes on the order tasks must be performed. Here is a graph of the dependencies.
The dependent array, a = [1, 2, 3, 4, 6, 5]. His principal tasks array, b = [7, 6, 4, 1, 2, 1]. Here is a graph of the dependencies:
From the graph, it is easy to see that task 6 must be performed before task 2 and vice versa. He can only complete one of those two tasks before the other, so he must choose either task 6 or 2. He can complete 7 - 1 = 6 tasks.Constraints
1 ≤ n ≤ 1050 ≤ m ≤ nMore Snowflake problems
- Minimum N-ary Tree Depth DeletionsPHONE SCREEN · Seen Jul 2026
- Simulate a Queued Multi-Rule Rate LimiterPHONE SCREEN · Seen Jul 2026
- Minimum Clicks Between Wiki PagesOA · Seen Jul 2026
- Closest Target CharacterPHONE SCREEN · Seen Jul 2026
- Horizontal Pod AutoscalerOA · Seen Jul 2026
- Minimum HeightOA · Seen Jul 2026
- Vowel SubstringOA · Seen Jun 2026
- String Formation (Also for AI/ML Software Engineer Intern :)OA · Seen Jun 2026