← LinkedIn Interview Insights

LinkedIn·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

LinkedIn software engineering interview focused on graph algorithms, specifically topological sort on a task dependency DAG. The follow-up pushed into parallel scheduling with a worker pool, which is where things got interesting.

Questions Asked (2)

Q1

Given a set of tasks with upstream dependencies forming a DAG, return a valid execution order for all tasks. If a cycle exists, report the DAG as invalid.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Started with Kahn's algorithm because tracking in-degrees felt cleaner to explain out loud.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Recognize this as a topological sort problem on a directed graph. Use Kahn's algorithm (BFS with in-degree tracking) to produce a valid order and detect cycles when the output size is less than the number of tasks. Alternatively, use DFS with recursion stack for cycle detection, but Kahn's is often preferred for its simplicity and explicit cycle detection.

Pro tip: Mention that Kahn's algorithm naturally detects cycles: if the topological order doesn't include all nodes, a cycle exists. Also, clarify that multiple valid orders may exist, so any correct order is acceptable.

1. Clarify the problem and assumptions

Confirm that tasks are nodes and dependencies are directed edges. Ask about input format (adjacency list or edge list), whether tasks are labeled, and if multiple valid orders are acceptable.

2. Choose the algorithm

Select Kahn's algorithm (BFS-based) for its intuitive cycle detection, or DFS with recursion stack. Explain the trade-offs: Kahn's is iterative and avoids recursion depth issues; DFS can be simpler for some but requires careful cycle detection.

3. Implement the algorithm

For Kahn's: compute in-degrees, enqueue nodes with in-degree 0, then repeatedly dequeue and reduce in-degrees of neighbors. For DFS: perform depth-first search, tracking visited and recursion stack to detect back edges.

4. Handle cycle detection

If using Kahn's, after processing, check if the result contains all tasks; if not, a cycle exists. If using DFS, a back edge indicates a cycle. Report the DAG as invalid in either case.

5. Analyze complexity and edge cases

State time complexity O(V+E) and space O(V+E). Discuss edge cases: empty graph, single node, disconnected components, and self-loops.

Key Points to Mention

  • Topological sorting is only possible for DAGs; cycles make it invalid.
  • Kahn's algorithm uses in-degree and a queue; if the result size < number of tasks, a cycle exists.
  • DFS approach uses a recursion stack to detect back edges; a visited set alone is insufficient.
  • Time and space complexity are O(V+E) for both approaches.
  • Multiple valid topological orders may exist; any is acceptable unless specified otherwise.
  • Edge cases: empty input, single task, disconnected graph, and self-loop (immediate cycle).

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

Q2

Extend your solution to support parallel execution with a worker pool of size k, returning batches of tasks that can run simultaneously. Also discuss how you'd handle dynamic task insertion.

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

This one tripped me up more than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the task dependency model and whether the worker pool should be static or dynamic. Then, describe a topological sort with in-degree tracking to identify ready tasks, and batch them into groups of up to k for parallel execution. Finally, explain how to handle dynamic insertion by updating dependencies and re-evaluating ready tasks without restarting the entire process.

Pro tip: Emphasize that the batch size should be min(k, number of ready tasks) to avoid underutilization, and discuss how dynamic insertion can be handled with a thread-safe queue and condition variables to wake up idle workers.

1. Clarify assumptions and constraints

Ask about the task graph structure (DAG?), whether tasks have uniform execution time, and if dynamic insertion can add dependencies to existing tasks. This shows you think about edge cases before diving into the solution.

2. Design the parallel execution model

Explain that you'll use a worker pool of size k and a thread-safe ready queue. Use topological sort with in-degree counts to identify tasks with no pending dependencies, and batch them into groups of up to k for simultaneous execution.

3. Handle dynamic task insertion

Describe how to integrate new tasks: update the dependency graph, adjust in-degrees, and if a new task has no dependencies, add it to the ready queue. Use synchronization primitives like mutexes and condition variables to safely notify workers.

4. Discuss trade-offs and optimizations

Compare static batching vs. dynamic scheduling, and mention potential bottlenecks like lock contention. Suggest optimizations such as work-stealing or using a concurrent queue to improve throughput.

5. Summarize and invite feedback

Recap the approach, highlighting how it ensures correctness and scalability. Ask if the interviewer wants to dive deeper into any specific aspect, showing collaborative problem-solving.

Key Points to Mention

  • Topological sort with in-degree tracking to identify ready tasks
  • Worker pool of size k with a thread-safe ready queue
  • Batching ready tasks into groups of up to k for parallel execution
  • Dynamic insertion: updating dependencies, in-degrees, and notifying workers
  • Synchronization using mutexes and condition variables to avoid race conditions
  • Trade-offs: static vs. dynamic scheduling, lock contention, and work-stealing

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