PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Uber

Detect cycle in directed dependency graph

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of graph theory and algorithmic problem-solving, specifically cycle detection in directed dependency graphs and the ability to reason about combined edge sets across multiple dependency arrays.

  • medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Detect cycle in directed dependency graph

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a directed dependency graph representing services in a system. - There are `n` services, labeled from `0` to `n - 1`. - You are given a list of directed edges `dependencies`, where each element is a pair `[a, b]` meaning **service `a` depends on service `b`** (i.e., there is a directed edge `a -> b`). Assume: - `1 <= n <= 10^5` - `0 <= a, b < n` - There may be zero or more edges. **Task:** 1. Implement a function that determines whether there is at least one cycle in this directed graph. - Return `true` if there is a cycle. - Return `false` otherwise. 2. Follow-up: Now you are given **multiple dependency arrays** instead of just one. Each array represents an additional list of edges on the same set of services. For example: - `dependencies1`, `dependencies2`, ..., `dependenciesk` Each `dependenciesi` is a list of `[a, b]` pairs as defined above. Treat the union of all these edges as a single directed graph and determine whether this combined graph contains any cycle. Describe the approach, data structures, and algorithm you would use, and analyze the time and space complexity.

Quick Answer: This question evaluates understanding of graph theory and algorithmic problem-solving, specifically cycle detection in directed dependency graphs and the ability to reason about combined edge sets across multiple dependency arrays.

Related Interview Questions

  • Implement stream queries and bounded-difference subarrays - Uber (medium)
  • Implement Minesweeper and Word Search - Uber (medium)
  • Implement Store Autocomplete - Uber (medium)
  • Simulate a Rank-Based Tournament - Uber (medium)
  • Implement Cache Eviction And Seat Assignment - Uber (medium)
Uber logo
Uber
Dec 8, 2025, 6:42 PM
Software Engineer
Technical Screen
Coding & Algorithms
4
0

You are given a directed dependency graph representing services in a system.

  • There are n services, labeled from 0 to n - 1 .
  • You are given a list of directed edges dependencies , where each element is a pair [a, b] meaning service a depends on service b (i.e., there is a directed edge a -> b ).

Assume:

  • 1 <= n <= 10^5
  • 0 <= a, b < n
  • There may be zero or more edges.

Task:

  1. Implement a function that determines whether there is at least one cycle in this directed graph.
    • Return true if there is a cycle.
    • Return false otherwise.
  2. Follow-up: Now you are given multiple dependency arrays instead of just one. Each array represents an additional list of edges on the same set of services. For example:
    • dependencies1 , dependencies2 , ..., dependenciesk
    Each dependenciesi is a list of [a, b] pairs as defined above. Treat the union of all these edges as a single directed graph and determine whether this combined graph contains any cycle.

Describe the approach, data structures, and algorithm you would use, and analyze the time and space complexity.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Uber•More Software Engineer•Uber Software Engineer•Uber 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.