Practice Remove Methods From Project
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are maintaining a project that has n methods numbered from 0 to n - 1. You are given two integers n and k, and a 2D integer array invocations, where invocations[i] = [ai, bi] indicates that method ai invokes method bi. There is a known bug in method k. Method k, along with any method invoked by it, either directly or indirectly, are considered suspicious and we aim to remove them. A group of methods can only be removed if no method outside the group invokes any methods within it. Return an array containing all the remaining methods after removing all the suspicious methods. You may return the answer in any order. If it is not possible to remove all the suspicious methods, none should be removed.
Source: Remove Methods From Project on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
n = 4, k = 1, invocations = [[1,2],[0,1],[3,2]]
[0,1,2,3]
# Example 2
n = 5, k = 0, invocations = [[1,2],[0,2],[0,1],[3,4]]
[3,4]
# Example 3
n = 3, k = 2, invocations = [[1,2],[0,1],[2,0]]
[]
Constraints
Related LeetCode Problems
Practice more problems similar to Remove Methods From Project.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.