52. Floyd Warshall Algorithm Code
Medium

Problem Statement

Implement the Floyd-Warshall algorithm to solve the all-pairs shortest path problem. Update the input adjacency matrix with shortest path distances.

Examples

1Example 1
Input:
{ "matrix": [ [ 0, 25 ], [ -1, 0 ] ] }
Output:
[ [ 0, 25 ], [ -1, 0 ] ]
2Example 2
Input:
{ "matrix": [ [ 0, 1, 43 ], [ 1, 0, 6 ], [ -1, -1, 0 ] ] }
Output:
[ [ 0, 1, 7 ], [ 1, 0, 6 ], [ -1, -1, 0 ] ]
3Example 3
Input:
{ "matrix": [ [ 0, 2, -1, -1 ], [ 1, 0, 3, -1 ], [ -1, -1, 0, -1 ], [ 3, 5, 4, 0 ] ] }
Output:
[ [ 0, 2, 5, -1 ], [ 1, 0, 3, -1 ], [ -1, -1, 0, -1 ], [ 3, 5, 4, 0 ] ]
Loading...

Sign in to Run Code and Submit