Shortest Pin Path Through Topics
Problem statement
Each row in topics lists the pins belonging to one topic. Treat every topic as an undirected clique: any two distinct pins in the same topic are connected by one unit-cost edge. Duplicate pin names inside a row have no additional effect.
Return the minimum number of pin-to-pin edges from start to destination. Return 0 when they are equal. Return -1 when either endpoint is absent or the destination is unreachable.
Function
minimumPinSteps(topics: String[][], start: String, destination: String) → intExamples
Example 1
topics = [["California","New York"],["New York","Cantonese cuisine"]]start = "California"destination = "Cantonese cuisine"return = 2California connects to New York, then to Cantonese cuisine.
Example 2
topics = [["a","b","c"]]start = "a"destination = "c"return = 1Pins in one topic are directly adjacent.
Constraints
0 <= topics.length <= 500.- The total number of pin occurrences is at most 5000.
- Pin names are nonempty.