Magicsheet logo

Remove Methods From Project

Medium
12.5%
Updated 8/1/2025

Remove Methods From Project

What is this problem about?

The Remove Methods From Project interview question models a software project as a directed graph where each method (node) may invoke other methods (directed edges). Given a "suspicious" method node, you must determine which methods can be safely removed — specifically, all methods that are exclusively reachable from the suspicious method and cannot be reached from any other "clean" method. Methods reachable from clean sources must be retained.

Why is this asked in interviews?

Bloomberg asks this graph problem because it mirrors real-world software analysis tasks: dead code elimination, dependency pruning, and refactoring. It tests graph traversal (BFS or DFS) combined with reachability analysis. Candidates must think carefully about the direction of edges and the distinction between "reachable only from suspicious" vs "reachable from clean methods too."

Algorithmic pattern used

The pattern is two-pass graph traversal (BFS/DFS). First, find all nodes reachable from the suspicious node using a forward traversal. Second, find all nodes reachable from each clean node (all nodes except the suspicious one) using another BFS/DFS. A node should be removed if it is in the suspicious reachable set but NOT in the clean reachable set. Nodes reachable from both sets must be kept.

Example explanation

Methods: 0, 1, 2, 3, 4. Suspicious: 1. Edges: 0→2, 1→2, 1→3, 3→4.

  • Suspicious reachable from 1: {1, 2, 3, 4}.
  • Clean sources: {0}. Reachable from 0: {0, 2}.
  • Methods reachable ONLY from suspicious (not from clean): {1, 3, 4}. (2 is also reachable from 0, so keep it.)

Remove: {1, 3, 4}. Keep: {0, 2}.

Common mistakes candidates make

  • Only doing one traversal from the suspicious node and removing everything reachable — this incorrectly removes methods also reachable from clean nodes.
  • Using an undirected graph approach when the problem requires directed traversal.
  • Not including the suspicious node itself in the removal set — it should also be removed.
  • Confusing "reachable from" with "can reach" — direction matters in this graph.

Interview preparation tip

For the Remove Methods From Project coding problem, the BFS and graph interview pattern with reachability analysis is the key. Practice building the adjacency list and running two BFS passes clearly. Bloomberg interviewers appreciate candidates who articulate the two-pass strategy before coding: "First I find what the suspicious method can reach, then I find what clean methods can reach, and remove the difference." This structured approach signals clarity of thought.

Similar Questions