PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Amazon

Determine if all courses can be completed

Last updated: Jun 13, 2026

Quick Overview

This question evaluates graph-theoretic dependency modeling and cycle-detection competency, measuring the ability to represent course prerequisites as a directed graph within the Coding & Algorithms domain for a Machine Learning Engineer role.

  • medium
  • Amazon
  • Coding & Algorithms
  • Machine Learning Engineer

Determine if all courses can be completed

Company: Amazon

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are building a planner for a training program with `n` courses labeled `0` through `n - 1`. You are given a list of prerequisite pairs `prerequisites`, where each pair `[course, prerequisite]` means `prerequisite` must be completed before `course` can be taken. Write a function that returns `true` if it is possible to complete all courses, and `false` otherwise. Clarifications: - A course may have multiple prerequisites. - The prerequisite graph may contain disconnected components. - If there is a dependency cycle, not all courses can be completed. Example: ```text n = 4 prerequisites = [[1, 0], [2, 1], [3, 2]] Output: true ``` Example: ```text n = 2 prerequisites = [[0, 1], [1, 0]] Output: false ```

Quick Answer: This question evaluates graph-theoretic dependency modeling and cycle-detection competency, measuring the ability to represent course prerequisites as a directed graph within the Coding & Algorithms domain for a Machine Learning Engineer role.

Related Interview Questions

  • Implement Datacenter Router Commands - Amazon (hard)
  • Implement Event Filtering and Queue Routing - Amazon (medium)
  • Replace Delimited Tokens in a String - Amazon (medium)
  • Minimize Circular Redistribution Cost - Amazon (medium)
  • Find the Most Common Visit Pattern - Amazon (hard)
Amazon logo
Amazon
May 30, 2026, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
0
0

You are building a planner for a training program with n courses labeled 0 through n - 1. You are given a list of prerequisite pairs prerequisites, where each pair [course, prerequisite] means prerequisite must be completed before course can be taken.

Write a function that returns true if it is possible to complete all courses, and false otherwise.

Clarifications:

  • A course may have multiple prerequisites.
  • The prerequisite graph may contain disconnected components.
  • If there is a dependency cycle, not all courses can be completed.

Example:

n = 4
prerequisites = [[1, 0], [2, 1], [3, 2]]
Output: true

Example:

n = 2
prerequisites = [[0, 1], [1, 0]]
Output: false

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amazon•More Machine Learning Engineer•Amazon Machine Learning Engineer•Amazon Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,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.