Compute task order and layered execution

Quick Overview

This question evaluates a candidate's understanding of graph algorithms and dependency resolution, covering concepts such as topological ordering and cycle detection.

Compute task order and layered execution

Company: Snowflake

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You have N tasks labeled 0..N-1 and prerequisite pairs (a, b) meaning task a must complete before task b can start. Return any valid execution order of all tasks, or an empty list if no such order exists. Additionally, return the tasks grouped by levels, where level i contains all tasks that can start only after all tasks in levels < i complete. Describe the algorithm, complexity, and how you detect cycles.

Quick Answer: This question evaluates a candidate's understanding of graph algorithms and dependency resolution, covering concepts such as topological ordering and cycle detection.

|Home/Coding & Algorithms/Snowflake
Snowflake logo
Snowflake
Sep 6, 2025, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
8
0

You have N tasks labeled 0..N-1 and prerequisite pairs (a, b) meaning task a must complete before task b can start. Return any valid execution order of all tasks, or an empty list if no such order exists. Additionally, return the tasks grouped by levels, where level i contains all tasks that can start only after all tasks in levels < i complete. Describe the algorithm, complexity, and how you detect cycles.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...