PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This problem evaluates graph connectivity and traversal concepts—specifically reasoning about adjacency representations, path existence, cycles, disconnected components, and missing-node edge cases—within the Coding & Algorithms domain at an implementation-level (medium) abstraction.

  • easy
  • Bloomberg
  • Coding & Algorithms
  • Software Engineer

Check connectivity between two subway stations

Company: Bloomberg

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You are given a description of subway stations A, B, C, D, E, ... as a graph. For each station, you are told which other stations it directly connects to (e.g., an adjacency list/map). Write a function that, given two station names start and end, returns whether it is possible to travel from start to end by following one or more connections (i.e., whether a path exists). Assume station names are strings. If a station is not present in the map, treat it as having no outgoing connections. Additionally, write a few test cases for your function (including cases with cycles, disconnected components, start==end, and missing stations).

Quick Answer: This problem evaluates graph connectivity and traversal concepts—specifically reasoning about adjacency representations, path existence, cycles, disconnected components, and missing-node edge cases—within the Coding & Algorithms domain at an implementation-level (medium) abstraction.

You are given a subway network as an adjacency map where each key is a station name and its value is a list of stations that can be reached directly from it. Write a function that returns whether it is possible to travel from a given start station to a given end station by following these connections. Treat the graph exactly as listed: you may only travel from a station to the stations in its adjacency list. If a connection is bidirectional, both directions must appear in the map. If a station is missing from the map, treat it as having no outgoing connections. A station is considered reachable from itself, even without taking any connections. The graph may contain cycles.

Constraints

  • 0 <= number of stations in the map <= 100000
  • 0 <= total number of listed connections <= 200000
  • Station names are strings
  • A station may appear in a neighbor list even if it is not a key in the map; such a station has no outgoing connections

Examples

Input: ({'A': ['B', 'C'], 'B': ['D'], 'C': [], 'D': ['E'], 'E': []}, 'A', 'E')

Expected Output: True

Explanation: One valid path is A -> B -> D -> E.

Input: ({'A': ['B'], 'B': ['C'], 'C': ['A', 'D'], 'D': []}, 'A', 'D')

Expected Output: True

Explanation: The graph contains a cycle A -> B -> C -> A, but D is still reachable through A -> B -> C -> D.

Input: ({'A': ['B'], 'B': [], 'C': ['D'], 'D': []}, 'A', 'D')

Expected Output: False

Explanation: A and D are in different disconnected components.

Input: ({'A': ['B'], 'B': ['A']}, 'B', 'B')

Expected Output: True

Explanation: A station is always reachable from itself.

Input: ({'A': ['B'], 'B': []}, 'X', 'B')

Expected Output: False

Explanation: X is not in the map, so it has no outgoing connections and cannot reach B.

Input: ({'A': ['B'], 'B': ['X']}, 'A', 'X')

Expected Output: True

Explanation: X is not a key in the map, but it can still be reached because B connects directly to X.

Input: ({}, 'A', 'B')

Expected Output: False

Explanation: With an empty graph, there are no connections to follow.

Hints

  1. This is a graph reachability problem. Try exploring from the start station using DFS or BFS.
  2. Keep a visited set so you do not get stuck in cycles by revisiting the same station repeatedly.
Last updated: Apr 19, 2026

Loading coding console...

PracHub

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

Related Coding Questions

  • Minimize Travel Assignment Cost - Bloomberg (medium)
  • Determine Balloon Popping Time - Bloomberg (medium)
  • Solve meeting and tree problems - Bloomberg (easy)
  • Minimize travel cost with two cities - Bloomberg (easy)
  • Design a data structure for dynamic top‑K frequency - Bloomberg (hard)