Company: Teradata

Difficulty: medium

Problem Statement

Shortest Path in a Weighted Undirected Graph You are given a connected, weighted, undirected graph with vertices numbered from `0` to `n - 1`. Find the minimum total weight of a path from `source` to `target`. Input Format The first line contains two integers `n` and `m`, the number of vertices and edges. The next `m` lines contain `u v w`, denoting an undirected edge between `u` and `v` with positive weight `w`. The final line contains `source target`. Output Format Print the minimum distance from `source` to `target`, or `-1` if no path exists. Constraints `1 <= n <= 100000`, `0 <= m <= 200000`, `0 <= u, v, source, target < n`, and `1 <= w <= 100000`. Notes Each input edge can be travelled in either direction. A path from a vertex to itself has distance `0`. Example Input ```text 4 4 0 1 4 0 2 1 2 1 2 1 3 1 0 3 ``` Output ```text 4 ```

More Teradata OA questionsInterview experiences