← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Pinterest has a bipartite graph in which every Pin belongs to one or more Boards. You are given two data sets:
Write a function int pinBoardDistance(String startPin, String targetPin, Map<String,Set<String>> pinToBoards, Map<String,Set<String>> boardToPins) that returns the minimum number of “hops” required to travel from startPin to targetPin, where a hop is defined as moving from a Pin to any Board that contains it, or from a Board to any Pin it contains. If the two pins are the same, return 0; if either pin does not exist or the target is unreachable, return –1. You should treat the graph as unweighted and undirected, and you must not modify the input maps.