Given one directional airport connections, devise a solution that can provide the route from Airport A to Airport B.
Implement 2 functions: one that adds a one-directional airport connection between 2 airports, and second that return out all possible routes between an origin and a destination. This could be done by implementing a class called AirMap that has two methods:
1
addConnection(start, destination) adds a ONE WAY connecting flight from start to destination2
getAllRoutes(start, destination) return all possible routes from start to destination irrespective of hopsA ----> B
B ----> A
A ----> C
C ----> A
A ----> D
D ----> A
B ----> C
C ----> B
B ----> D
D ----> B
airMap.getAllRoutes('C', 'D');
[[C,A,B,D,]
[C,A,D,]
[C,B,A,D,]
[C,B,D,]]
public class Solution {
public class AirMap {
HashMap<String, ArrayList<String>> connections = new HashMap<>();
public void addConnection(String start, String end){
}
public List<List<String>> getAllRoutes(String start, String end){
}
}