Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6376 |

@mb1973 | 5594 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3412 |

Complete Leaderboard | |

Handle | Score |

@codersgroup18 | 783 |

@Manikanta punnam | 605 |

@sriramgoparaju99 | 582 |

@rdakka | 538 |

@praveenbgp6 | 529 |

@prankursharma31 | 518 |

@yashkaril4 | 517 |

@purohitmn02 | 467 |

@sonamnigam1999 | 443 |

@sonamkumari63928 | 441 |

@shubhamstudent5 | 433 |

Complete Leaderboard |

The problem is to find shortest distances between every pair of vertices in a given edge weighted directed Graph. The Graph is represented as adjancency matrix, and the matrix denotes the weight of the edegs (if it exists) else -1. **Do it in-place.**

**Example 1:**

**Input: **matrix = {{0,25},{-1,0}}
**Output: **{{0,25},{-1,0}}
**Explanation: **The shortest distance between
every pair is already given(if it exists).

**Example 2:**

**Input: **matrix = {{0,1,43},{1,0,6},{-1,-1,0}}
**Output: **{{0,1,7},{1,0,6},{-1,-1,0}}
**Explanation: **We can reach 3 from 1 as 1->2->3
and the cost will be 1+6=7 which is less than
43.

**Your Task:**

You don't need to read, return or print anything. Your task is to complete the function **shortest_distance() **which takes the matrix as input parameter and modify the distances for every pair in-place.

**Expected Time Complexity: **O(n^{3})

**Expected Space Compelxity: **O(1)

**Constraints:**

1 <= n <= 100

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Floyd Warshall

...