All Simple Paths in a Cyclic Directed Graph
Updated
Problem statement
Given a directed graph with nodes 0..n-1 and its edges, return every simple path from source to target. A simple path never visits the same node twice.
Return the paths in the order a depth-first search finds them when it tries each node's neighbors from smallest to largest.
Function
allSimpleDirectedPaths(n: int, edges: int[][], source: int, target: int) → int[][]Examples
Example 1
n = 4edges = [[0,1],[1,2],[2,0],[1,3],[2,3],[0,3]]source = 0target = 3return = [[0,1,2,3],[0,1,3],[0,3]]A path cannot repeat a node, so the search never goes back around the cycle through 0, 1, 2. The three paths that reach the target are listed in depth-first order.
Constraints
1 <= n <= 15.- Directed edges are unique.
More Bloomberg LP Onsite Interview questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Park Train Cars by PreferenceMercor · ONSITE INTERVIEWMercor interview questions
- Count Prefix Paths in a Character GraphGoogle · PHONE SCREENGoogle interview questions
- Directional Tiles: Find a Valid Reconfiguration PathDuolingo · PHONE SCREENDuolingo interview questions
- Attraction Route Without Reusing TrailsWhatNot · PHONE SCREENWhatNot interview questions
- Enumerate Directed Paths and CyclesByteDance · PHONE SCREENByteDance interview questions
- Detonate the Maximum BombsZomato / Eternal · PHONE SCREENZomato / Eternal interview questions
- Task Build Order and File-Change RerunsVanta · PHONE SCREEN
- Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Course ScheduleOracle · ONSITE INTERVIEWOracle interview questions
- Package Install OrderVerily · ONSITE INTERVIEW
Interview reports that mention this question
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)