Reported July 2026
Sofigraph

Reachable Nodes in a Directed Graph

Reported by candidates from Sofi's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Sofi OA. Under 2s to a working solution.
Founder's read

The Sofi reachable-nodes question, reported in July 2026, comes with a detail that gives away the whole game: the graph can have cycles and self-loops, and your code must not hang. It's a directed graph traversal. Given an adjacency list and a start id, return every vertex you can reach, start included. The reported prompt came from a staff-level onsite, but the executable version is plain DFS or BFS with a visited set. If you're taking this OA in the next couple of days, the traversal is easy. The part that bites is the deep-chain constraint. StealthCoder sits invisibly as a safety net if you blank on the iterative version.

The problem

🐒 FastPrep source match note: This practice version is based on a reported SoFi Staff Engineer onsite question last seen on July 3, 2026. The original asked candidates to return reachable Vertex objects from a directed graph. FastPrep uses unique vertex ids and an adjacency-list input so the same traversal task can run in the workspace; the coding goal and interview discussion path are a 90%+ match to the reported prompt and backed by the provided source screenshot. 🐝
You are given a directed graph. In the original interview prompt, the graph is represented by Vertex objects, and each vertex contains a collection of outgoing neighbors.
In this executable FastPrep version, each vertex is represented by a unique string id. The input graph is an adjacency list where each row starts with a vertex id, followed by that vertex's outgoing neighbors. A row with only one value represents a vertex with no outgoing neighbors.
Implement the function reachableNodes.
The function should return all vertices that can be reached from start, including start itself.
The graph may contain cycles. Your implementation must avoid visiting the same vertex repeatedly and must not get stuck in an infinite loop.
The returned collection does not need to be in any specific order.
Clarifications / Corner Cases
The graph is directed.
The result should include the starting vertex.
The graph may contain cycles or self-loops.
The graph may be disconnected.
A vertex may have no outgoing neighbors.
The output order does not matter.
Assume start is not null.
Assume each vertex can be uniquely identified, either by object identity or by a unique id/name.
Follow-up / Interview Discussion
How would you implement this using DFS?
How would you implement this using BFS?
What state is necessary to prevent repeated work or infinite loops?
Is a parent map necessary for this problem? Why or why not?
What can go wrong with recursive DFS on a very deep graph?
When would BFS be preferable to DFS?
If the graph has thousands of vertices in a long chain, what implementation choice is safer in Java?

Function
reachableNodes(graph: String[][], start: String) → String[]

Examples
Example 1
graph = [["A", "B"], ["B", "C", "D"], ["C"], ["D", "E"], ["E", "B"]]
start = "A"
return = ["A", "B", "C", "D", "E"]
Given the directed graph:
A -> B
B -> C, D
D -> E
E -> B
Starting from A, we can reach B. From B, we can reach C and D. From D, we can reach E. From E, we go back to B, but B has already been visited.
One valid return value is [A, B, C, D, E].
Example 2
graph = [["A", "B"], ["B"], ["C", "D"], ["D"]]
start = "A"
return = ["A", "B"]
C and D exist in the graph, but they are not reachable from A.
Example 3
graph = [["A", "A"]]
start = "A"
return = ["A"]
A has a self-cycle. The algorithm should include A once and stop.

Constraints
1 <= number of vertices <= 100,000
0 <= number of directed edges <= 300,000
The graph may be sparse, dense, shallow, or very deep.
Only vertices reachable from start need to be returned.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a visited set plus a traversal. Build a map from vertex id to its neighbor list from the rows, then run BFS or iterative DFS from start. Mark a vertex visited when you push it, not when you pop it, so duplicates never enter the queue. That handles cycles and self-loops like [A, A] for free. The common pitfall is recursive DFS. The constraints allow 100,000 vertices in a long chain, so recursion can overflow the stack. Use an explicit stack or a queue. Other traps: vertices with no row in the map (treat as no neighbors), and forgetting to include start itself. You don't need a parent map, since you only return reachable nodes, not paths. Complexity is O(V + E) time and space. If you freeze on the iterative loop during the live OA, StealthCoder is the hedge that shows you a clean version.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Reachable Nodes in a Directed Graph cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Sofi's OA.

Sofi reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Reachable Nodes in a Directed Graph FAQ

How hard is the Sofi reachable nodes problem really?+

Easy to medium. It's a standard graph traversal with a visited set. The difficulty is in the details: cycles, self-loops, disconnected components, and a graph up to 100,000 vertices that can be one long chain. If you've written BFS before, you can finish this quickly.

What's the trick to avoid infinite loops?+

Keep a visited set and check it before adding a neighbor to the stack or queue. Mark on push, not on pop. That way a cycle like A to B to A, or a self-loop like A to A, gets seen once and then ignored.

Should I use DFS or BFS here?+

Either gives a correct answer since order doesn't matter. BFS with a queue is the safest default. If you pick DFS, write it iteratively with an explicit stack, because a recursive version can blow the stack on a deep chain of thousands of vertices.

Do I need a parent map?+

No. A parent map is for reconstructing paths. This problem only asks which vertices are reachable, so a visited set is the only state you need. Mentioning that clearly is a good answer if the follow-up comes up.

How do I prepare for this in 48 hours?+

Write BFS and iterative DFS on an adjacency list from scratch, twice. Test with a cycle, a self-loop, a disconnected component, and a vertex with no neighbors. Know the O(V + E) complexity and why recursion is risky on deep graphs. That covers the likely follow-ups.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Sofi.

OA at Sofi?
Invisible during screen share
Get it