PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Snowflake

Schedule prerequisite classes with retakes

Last updated: Mar 29, 2026

Quick Overview

This question evaluates competency in graph algorithms, dependency resolution, stateful scheduling, and robust error handling within the Coding & Algorithms domain.

  • easy
  • Snowflake
  • Coding & Algorithms
  • Software Engineer

Schedule prerequisite classes with retakes

Company: Snowflake

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Onsite

## Problem You are building a course-taking engine. Each course is represented as an object: - `id` (unique identifier) - `prevCoursesList`: a list of prerequisite course IDs that must be **passed** before this course can be attempted. You are given: - `roots`: a list of **target** course IDs the student ultimately wants to complete. - An API `didPass(courseId) -> bool` that can be called **each time you attempt** a course. If it returns `false`, the student failed that attempt and must retake the course later. ### Rules 1. A course can be **attempted** only after all its prerequisites have been **passed**. 2. When a course is attempted: - If `didPass(id)` returns `true`, mark it as passed. - If it returns `false`, the course must be retaken later (i.e., re-queued for another attempt). 3. The input only provides prerequisite pointers (`course -> prerequisites`). You must first discover all involved courses reachable from `roots` and build any additional relationships you need (e.g., prerequisite → dependent adjacency). ### Task Implement a function that returns the sequence of course IDs in the order they were **attempted** until: - all `roots` have been passed, or - you detect it is impossible (e.g., a prerequisite cycle), or - a course exceeds `maxRetries` failed attempts. ### Output Return: - `attemptOrder`: list of attempted course IDs (including retries), if successful. - Otherwise, return/throw an error indicating the reason (cycle detected or retries exceeded). ### Constraints (reasonable assumptions) - Up to ~1e5 courses and ~2e5 prerequisite edges may be involved after expanding from `roots`. - `maxRetries` is a small integer (e.g., 3–10). ### Edge cases to handle - Shared prerequisites among multiple roots. - Duplicate IDs in `roots`. - Missing prerequisite IDs (treat as invalid input). - Cycles in prerequisite dependencies. - Courses that repeatedly fail and exceed `maxRetries`.

Quick Answer: This question evaluates competency in graph algorithms, dependency resolution, stateful scheduling, and robust error handling within the Coding & Algorithms domain.

Related Interview Questions

  • Solve Array Distance and Wiki Navigation - Snowflake (medium)
  • Implement Document Predicate APIs - Snowflake (medium)
  • Find Shortest Wiki Click Path - Snowflake (medium)
  • Solve three coding rounds - Snowflake (medium)
  • Minimize coins with overpay and change - Snowflake (hard)
Snowflake logo
Snowflake
Mar 1, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
11
0
Loading...

Problem

You are building a course-taking engine.

Each course is represented as an object:

  • id (unique identifier)
  • prevCoursesList : a list of prerequisite course IDs that must be passed before this course can be attempted.

You are given:

  • roots : a list of target course IDs the student ultimately wants to complete.
  • An API didPass(courseId) -> bool that can be called each time you attempt a course. If it returns false , the student failed that attempt and must retake the course later.

Rules

  1. A course can be attempted only after all its prerequisites have been passed .
  2. When a course is attempted:
    • If didPass(id) returns true , mark it as passed.
    • If it returns false , the course must be retaken later (i.e., re-queued for another attempt).
  3. The input only provides prerequisite pointers ( course -> prerequisites ). You must first discover all involved courses reachable from roots and build any additional relationships you need (e.g., prerequisite → dependent adjacency).

Task

Implement a function that returns the sequence of course IDs in the order they were attempted until:

  • all roots have been passed, or
  • you detect it is impossible (e.g., a prerequisite cycle), or
  • a course exceeds maxRetries failed attempts.

Output

Return:

  • attemptOrder : list of attempted course IDs (including retries), if successful.
  • Otherwise, return/throw an error indicating the reason (cycle detected or retries exceeded).

Constraints (reasonable assumptions)

  • Up to ~1e5 courses and ~2e5 prerequisite edges may be involved after expanding from roots .
  • maxRetries is a small integer (e.g., 3–10).

Edge cases to handle

  • Shared prerequisites among multiple roots.
  • Duplicate IDs in roots .
  • Missing prerequisite IDs (treat as invalid input).
  • Cycles in prerequisite dependencies.
  • Courses that repeatedly fail and exceed maxRetries .

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Snowflake•More Software Engineer•Snowflake Software Engineer•Snowflake Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.