Bloomberg | Phone Screen(2020) | All Paths Between Source & Destination
Anonymous User
1007

I took my first stage phone interview on the 7th of February 2020.

It started off with the interviewer telling me about himself and the work he did.

The problem was framed as a Design Problem. There is a class called Air Strip, it has two methods:

  1. addPath(String source, String destination)
  2. printAllPathsBetween(String source, String destination)

Using the correct algorithms and datastructures implement both methods.

For the first problem, I used a HashMap with the as the key and a set of strings as the value. The former represents the source and the latter the destination.

In the second problem, I stumbled a bit but was able to implement a DFS approach using a stack that the interviewer was satisfied with.

Here's an example of how your method would be called:

addPath('A', 'B');
addPath('B', 'C');
addPath('B', 'C');
addPath('A', 'C');
addPath('A', 'D');
addPath('D', 'C');
addPath('F', 'E');

You should ignore when a path is added twice. I used a Set to handle this.

printAllPathsBetween('A', 'C') should return:
'A -> C'
'A -> B -> C'
'A -> D -> C'

printAllPathsBetween('E', 'A') should return:
" " i.e emptyString
Now waiting to hear back.

Comments (4)