Find a Valid Task Execution Order with Dependencies

Last updated: June 30, 2026

Quick Overview

The candidate is asked to find a valid order of task execution given a set of tasks and their dependencies.

Salesforce
Coding & Algorithms
Software Engineer
Salesforce
June 30, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

1

0

12 solved


The candidate is asked to find a valid order of task execution given a set of tasks and their dependencies.

This question is commonly asked during onsite interviews for software engineering roles to assess a candidate's problem-solving skills and understanding of graph theory. The interviewer evaluates the candidate's ability to implement algorithms that can handle directed acyclic graphs (DAGs) and their approach to managing dependencies effectively. This question also tests the candidate's coding skills and their ability to write efficient and clean code.

What the Interviewer Expects
  • Clearly explain the problem and the approach to solving it.
  • Identify the data structure needed to represent tasks and dependencies.
  • Implement a topological sort algorithm to determine the valid execution order.
  • Discuss the time and space complexity of the solution.
  • Provide a working code example that handles edge cases.
Key Topics to Cover
Graph Theory
Topological Sorting
Data Structures
Algorithm Complexity
Dependency Resolution
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you handle cyclic dependencies?
  • Can you optimize your solution further?
  • What would you change if tasks could have multiple dependencies?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Approach

To solve the problem of finding a valid task execution order given dependencies, we can represent the tasks and their dependencies as a directed graph. Each task is a node, and a directed edge from ta...

Algorithm

We can use Kahn's algorithm for topological sorting, which involves the following steps:

  1. Initialize an in-degree array to count incoming edges for each node.
  2. Populate the in-degree array based o...

Submit Your Answer
Markdown supported

Related Questions