← 返回 pinterest 的题目列表Bus Routes
类型:online_judge
Search companies, questions, guides…
⌘
K
Interview Copilot
中
Calculate Pin Jumps in Graph
pinterest
Given a list of pins in the graph, design an algorithm to calculate the minimum number of jumps needed from one pin to another pin.
Input
An integer n indicating the number of pins.
An integer list edges where each element is a list of two integers [u, v] indicating a connection between pin u and pin v.
Two integers start and end specifying the starting and ending pin.
Output
An integer representing the minimum number of jumps required from start to end.
Example
Input: n = 4, edges = [[0, 1], [1, 2], [2, 3]], start = 0, end = 3
Output: 3
Constraints
1 <= n <= 1000
u, v in each edges element have 0 <= u, v < n
0 <= start, end < n
Example
Input
4
[[0, 1], [1, 2], [2, 3]]
0
3