← Salesforce Interview Insights

Salesforce·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Salesforce SWE interview with a topological sort problem dressed up as a CI/CD task scheduler. Pretty classic graph question but the build system framing threw me for a second before I realized what they were actually asking.

Questions Asked (1)

Q1

You're building a task scheduler for a CI/build system. Given n tasks and a list of dependency pairs where [a, b] means task a can't start until task b finishes, return a valid execution order for all tasks. If a cycle exists, return an empty list.

Algorithms & Data StructuresSystem Design
Author's notes

Took me a moment to strip away the build system flavor and see it was just topological sort.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the tasks and dependencies as a directed graph and use topological sorting (Kahn's algorithm or DFS) to produce a valid execution order. Detect cycles by checking if all nodes are processed (Kahn's) or if a back edge is found (DFS).

Pro tip: Clarify the direction of dependencies upfront: [a, b] means a depends on b, so b must come before a. This avoids reversing edges and producing an incorrect order.

1. Clarify and Model

Confirm the dependency direction and represent tasks as nodes and dependencies as directed edges. For [a, b], add edge b -> a (b must precede a).

2. Choose Algorithm

Select topological sort: Kahn's algorithm (BFS with in-degrees) or DFS with temporary/permanent marks. Both handle cycle detection.

3. Implement Topological Sort

For Kahn's: compute in-degrees, enqueue nodes with in-degree 0, process and decrement neighbors. For DFS: recursively visit dependencies, detect back edges.

4. Detect Cycles

If Kahn's processes fewer than n nodes, a cycle exists. For DFS, if a back edge is found, return empty list.

5. Return Result

Return the topological order as a list of tasks. If cycle detected, return an empty list.

Key Points to Mention

  • Topological sorting is the standard approach for dependency resolution.
  • Kahn's algorithm uses in-degrees and a queue; DFS uses recursion with visited states.
  • Cycle detection is inherent: Kahn's fails if not all nodes are processed; DFS detects back edges.
  • Time complexity is O(V+E), space O(V+E) for graph representation.
  • Edge direction: [a, b] means b -> a (b before a).
  • Handling disconnected graphs: process all nodes, not just those reachable from one start.

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