FastPrepAll Simple Paths in an Undirected Graph
Problems/All Simple Paths in an Undirected Graph

All Simple Paths in an Undirected Graph

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in firsthand Bloomberg new grad phone and onsite interviews. Here the neighbors are sorted, and you return the simple paths in alphabetical order.

Given an undirected 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. This is the same as sorting the paths by comparing their node numbers from left to right.

Function

allSimplePaths(n: int, edges: int[][], source: int, target: int) → int[][]

Examples

Example 1

n = 4edges = [[0,1],[1,3],[0,2],[2,3],[1,2]]source = 0target = 3return = [[0,1,2,3],[0,1,3],[0,2,1,3],[0,2,3]]

From the source, the search tries smaller neighbors first, so the two paths whose second node is one come before the two whose second node is two. No path visits a node twice.

Constraints

  • 1 <= n <= 15.
  • Edges are unique undirected pairs.
  • Source and target are valid distinct nodes.

More Bloomberg LP Phone Screen 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
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
  • Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
  • Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
  • Design Browser HistoryPHONE 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 Experienced Design & More: 126 Questions (Part 2 of 2)

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)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int[][] allSimplePaths(int n, int[][] edges, int source, int target) {
      // Write your code here.
    }
}
Checking account…