2dbi
Home/Palantir/Implement a Graph: Add/Remove Nodes & Edges, Path Search, Cycle Detection
PPalantir·DSASWE-2Technical Phone Screen

Implement a Graph: Add/Remove Nodes & Edges, Path Search, Cycle Detection

Problem

Implement a graph supporting addNode, removeNode, addEdge, removeEdge, hasPath(a, b), and hasCycle().

Example

addEdge(A,B); addEdge(B,C); hasPath(A,C) -> true; addEdge(C,A); hasCycle() -> true

Constraints

  • Directed graph; handle removal of nodes with incident edges

What Palantir looks for

Clean API and data model; correct DFS for path/cycle. Expect probing on time/space complexity and design choices.

added 6 days ago
LeadersAccount