Description
Solutions
Submission
Task Master (Also for Infra Automation Intern)
🤘 INTERN

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 Description

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 tasks
  • a[a[0],...a[n-1]]: an array of integers, the dependent tasks
  • b[b[0],...b[n-1]]: an array of integers, the primary tasks
  • Example 1:

    Input:  n = 7, a = [1, 2, 3, 4, 6, 5], b = [7, 6, 4, 1, 2, 1]
    Output: 6
    Explanation:
    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 ≤ 105
    • 0 ≤ m ≤ n
    • Each task depends on at most one other task.
    Thumbnail 0
    Testcase

    Result
    Case 1

    input:

    output: