FastPrepShortest Pin Path Through Topics
Problems/Shortest Pin Path Through Topics

Shortest Pin Path Through Topics

Pinterest logoPinterest● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report establishes the task identity and central capability. This practice contract supplies only the portable interface, deterministic boundary rules, and output serialization needed for consistent execution.

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) → int

Examples

Example 1

topics = [["California","New York"],["New York","Cantonese cuisine"]]start = "California"destination = "Cantonese cuisine"return = 2

California connects to New York, then to Cantonese cuisine.

Example 2

topics = [["a","b","c"]]start = "a"destination = "c"return = 1

Pins 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.

More Pinterest problems

  • Gaussian Naive Bayes Classifier (Machine Learning OA)OA · Seen Nov 2026
  • Top K Pins with Insert and QueryPHONE SCREEN · Seen Nov 2026
  • Pins Violation Log QueriesPHONE SCREEN · Seen Nov 2026
All Pinterest interview questionsSee Pinterest hiring insights
Saved
class Solution {
    public int minimumPinSteps(String[][] topics, String start, String destination) {
      // write your code here
    }
}
Checking account…