FastPrepValidate a Course Prerequisite Order
Problems/Validate a Course Prerequisite Order

Validate a Course Prerequisite Order

Snowflake logoSnowflake● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Checking a course order is about 90% the same as the reported question. This exercise comes from a collection of interview-prep questions, not from one dated interview. We chose these. The order must include every course exactly once. We also set how an invalid array is handled, the function signature, the limits and the examples.

There are n courses numbered from 0 to n - 1. Every row [course, previous] in prerequisites means that previous must appear before course.

Complete isValidOrder. Given a proposed integer array order, return true if it contains every course ID exactly once and places each required course before the course that depends on it. Otherwise return false.

Any valid complete order is acceptable; it does not need to be sorted or be the smallest possible order. Repeated prerequisite rows repeat the same rule. A self-prerequisite makes every proposed order invalid. Reject an order with repeated IDs, missing courses, or IDs outside the course range. Do not try to fix the proposed array.

Function

isValidOrder(n: int, prerequisites: int[][], order: int[]) → boolean

Examples

Example 1

n = 3prerequisites = [[1,0],[2,1]]order = [0,1,2]return = true

Each prerequisite appears before its dependent course.

Example 2

n = 3prerequisites = [[1,0],[2,1]]order = [0,2,1]return = false

Course 2 appears before its required course 1.

Example 3

n = 3prerequisites = []order = [0,0,2]return = false

The proposed array repeats course 0 and omits course 1, even though there are no prerequisite edges.

Constraints

  • 1 <= n <= 200.
  • 0 <= prerequisites.length <= 5000. Each row has two integers in [0, n - 1]; repeated rows and self-prerequisites are permitted.
  • 0 <= order.length <= n + 1.
  • Every entry of order is an integer in [-1, n]. Values outside the valid course range are possible and must be rejected.

More Snowflake Phone Screen questions

  • Minimum StackPHONE SCREEN · Seen Nov 2026
  • Design In-Memory File SystemPHONE SCREEN · Seen Nov 2026
  • Merge Two Binary TreesPHONE SCREEN · Seen Nov 2026
  • Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
  • Minimum Edits to a Perfect Binary TreePHONE SCREEN · Seen Nov 2026
  • Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
  • Minimum Index Distance Between Person and CakeOA · PHONE SCREEN · Seen Nov 2026
  • Minimum N-ary Tree Depth DeletionsOA · PHONE SCREEN · Seen Nov 2026
  • Sum of Binary Tree Boundary NodesOA · PHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Task Build Order and File-Change RerunsVanta · PHONE SCREEN
  • Course ScheduleByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
  • Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Merge Event PreferencesAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
  • Network Layer Execution OrderNVIDIA · PHONE SCREENNVIDIA interview questions
  • Task Scheduler with Prerequisites and Execution PathsBrex · PHONE SCREEN
  • All Halfway Courses Across Course TracksCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Course Schedule Cycle DetectionGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Dependency-Aware Task SchedulerRippling · PHONE SCREENRippling interview questions
  • Build Packages as Dependencies Are DiscoveredMongoDB · PHONE SCREENMongoDB interview questions

Snowflake interview experiences

  • Snowflake AI Coding Interview, Experienced Hires: 3 Experiences
All Snowflake interview questionsSee Snowflake hiring insights
Saved
class Solution {
    public boolean isValidOrder(int n, int[][] prerequisites, int[] order) {
        // Write your code here.
    }

}
Checking account…