FastPrepJob Schedule with One Initial Ready Job
Problems/Job Schedule with One Initial Ready Job

Job Schedule with One Initial Ready Job

Datadog logoDatadog● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The firsthand phone-screen report describes a dependency-based job schedule, similar to Course Schedule, with only one initial zero-indegree job and a BFS approach. This exercise defines indexed before/after pairs, a boolean feasibility result, cycle cases, duplicate edges and finite bounds. The core task matches the report at about 85%.

There are jobCount jobs with IDs 0 through jobCount - 1. Each pair [before, after] in dependencies requires job before to finish before job after can start.

The original graph has exactly one job with no incoming dependency. Determine whether all jobs can finish. Return true if a valid ordering exists and false otherwise. Do not return the ordering itself.

A job that depends on itself creates a cycle. Repeating the same dependency does not add a new logical restriction; implementations that count repeated edges must also remove every copy when processing its parent. More than one job may become ready later, even though only one is ready initially.

Function

canFinishJobs(jobCount: int, dependencies: int[][]) → boolean

Examples

Example 1

jobCount = 4dependencies = [[0,1],[0,2],[1,3],[2,3]]return = true

Only job 0 is ready initially. Finishing it makes 1 and 2 ready. After both finish, job 3 can finish. For example, order 0,1,2,3 completes every job.

Example 2

jobCount = 3dependencies = [[1,2],[2,1]]return = false

Job 0 is the only initial zero-indegree job, but jobs 1 and 2 depend on each other. Completing the available job does not remove that disconnected cycle, so all jobs cannot finish.

Example 3

jobCount = 1dependencies = []return = true

The only job has no dependency and is the sole initial ready job. It can finish immediately.

Constraints

  • 1 <= jobCount <= 200
  • 0 <= dependencies.length <= 1000
  • Every dependency row has exactly two integers in [0, jobCount - 1].
  • Exactly one job has zero incoming edges in the original graph.
  • Self dependencies and repeated dependency rows are allowed.

More Datadog problems

  • Query Log MatchPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Delete a Filesystem TreePHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Grouped-Query Attention Forward PassPHONE SCREEN · Seen Jun 2026
All Datadog interview questionsSee Datadog hiring insights
Saved
public boolean canFinishJobs(int jobCount, int[][] dependencies) {
    // Write your code here.
}
Checking account…