← Veeva Systems Interview Insights

Veeva Systems·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Veeva Systems coding round, one question the whole time. It was a topological sort problem dressed up with some extra requirements and I spent more time second-guessing my cycle detection than actually coding it.

Questions Asked (1)

Q1

You're given a directed graph as an adjacency map where each key points to a list of tasks that depend on it. Implement a function that returns a valid execution order of all tasks reachable from a given starting node, with prerequisites always appearing first. Break ties alphabetically, detect any cycles, and explain the time and space complexity of your solution.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The core of it is just topological sort with DFS and a visited set for cycle detection, but the alphabetical tie-breaking tripped me up.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the graph semantics and constraints, then implement a topological sort using Kahn's algorithm with a min-heap to ensure alphabetical tie-breaking. Detect cycles by comparing the number of processed nodes to the total reachable nodes, and analyze complexity based on the reachable subgraph.

Pro tip: Explicitly state that you are only considering the reachable subgraph from the start node, and use a min-heap instead of a queue to handle alphabetical ordering efficiently. This shows attention to detail and avoids unnecessary work on unreachable nodes.

1. Clarify graph semantics and constraints

Confirm that the adjacency map represents dependencies (key must execute before its list) and that we only consider nodes reachable from the given start. Ask about input size, cycle handling, and whether the graph is guaranteed to be a DAG.

2. Choose algorithm and data structures

Select Kahn's algorithm (BFS-based topological sort) for its natural cycle detection. Use a min-heap for zero-indegree nodes to break ties alphabetically, and compute indegrees only for reachable nodes.

3. Implement reachability and indegree calculation

Perform a DFS/BFS from the start node to collect all reachable nodes. For each reachable node, compute its indegree by counting incoming edges from other reachable nodes.

4. Execute topological sort with cycle detection

Initialize a min-heap with reachable nodes having indegree zero. Repeatedly extract the smallest node, append to result, and decrement indegrees of its neighbors, adding any that become zero. If the result size is less than the number of reachable nodes, a cycle exists.

5. Analyze complexity and discuss trade-offs

State time complexity as O(V + E log V) due to heap operations, where V and E are the number of reachable nodes and edges. Space complexity is O(V + E) for storing the graph, indegrees, heap, and result. Mention that using a queue would give O(V+E) but without alphabetical order.

Key Points to Mention

  • Topological sorting is appropriate for dependency resolution, and Kahn's algorithm naturally detects cycles.
  • Using a min-heap ensures alphabetical tie-breaking among available tasks.
  • Only nodes reachable from the start node should be considered, which affects complexity analysis.
  • Cycle detection by comparing processed nodes to total reachable nodes.
  • Time complexity: O(V + E log V) with heap; space complexity: O(V + E).
  • Edge cases: empty graph, start node not in graph, self-loops, and disconnected components.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.