3310. Remove Methods From Project Medium
1/**
2 * [3310] Remove Methods From Project
3 *
4 * You are maintaining a project that has n methods numbered from 0 to n - 1.
5 * 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.
6 * 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.
7 * A group of methods can only be removed if no method outside the group invokes any methods within it.
8 * 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.
9 *
10 * <strong class="example">Example 1:
11 * <div class="example-block">
12 * Input: <span class="example-io">n = 4, k = 1, invocations = [[1,2],[0,1],[3,2]]</span>
13 * Output: <span class="example-io">[0,1,2,3]</span>
14 * Explanation:
15 * <img alt="" src="https://assets.leetcode.com/uploads/2024/07/18/graph-2.png" style="width: 200px; height: 200px;" />
16 * Method 2 and method 1 are suspicious, but they are directly invoked by methods 3 and 0, which are not suspicious. We return all elements without removing anything.
17 * </div>
18 * <strong class="example">Example 2:
19 * <div class="example-block">
20 * Input: <span class="example-io">n = 5, k = 0, invocations = [[1,2],[0,2],[0,1],[3,4]]</span>
21 * Output: <span class="example-io">[3,4]</span>
22 * Explanation:
23 * <img alt="" src="https://assets.leetcode.com/uploads/2024/07/18/graph-3.png" style="width: 200px; height: 200px;" />
24 * Methods 0, 1, and 2 are suspicious and they are not directly invoked by any other method. We can remove them.
25 * </div>
26 * <strong class="example">Example 3:
27 * <div class="example-block">
28 * Input: <span class="example-io">n = 3, k = 2, invocations = [[1,2],[0,1],[2,0]]</span>
29 * Output: <span class="example-io">[]</span>
30 * Explanation:
31 * <img alt="" src="https://assets.leetcode.com/uploads/2024/07/20/graph.png" style="width: 200px; height: 200px;" />
32 * All methods are suspicious. We can remove them.
33 * </div>
34 *
35 * Constraints:
36 *
37 * 1 <= n <= 10^5
38 * 0 <= k <= n - 1
39 * 0 <= invocations.length <= 2 * 10^5
40 * invocations[i] == [ai, bi]
41 * 0 <= ai, bi <= n - 1
42 * ai != bi
43 * invocations[i] != invocations[j]
44 *
45 */
46pub struct Solution {}
47
48// problem: https://leetcode.com/problems/remove-methods-from-project/
49// discuss: https://leetcode.com/problems/remove-methods-from-project/discuss/?currentPage=1&orderBy=most_votes&query=
50
51// submission codes start here
52
53impl Solution {
54 pub fn remaining_methods(n: i32, k: i32, invocations: Vec<Vec<i32>>) -> Vec<i32> {
55 vec![]
56 }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_3310() {
67 }
68}
69
Back
© 2025 bowen.ge All Rights Reserved.