Shortest Path

Shortest Path

Twenty-five questions on shortest-path algorithms, including Dijkstra's, Bellman-Ford, and Floyd-Warshall.

Cheapest Flights Within K Stops

medium
There are n cities connected by some number of flights.

Digit Operations to Make Two Integers Equal

medium
You are given two integers n and m that consist of the same number of digits.

Evaluate Division

medium
You are given an array of variable pairs equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] represent the equation Ai / Bi = values[i].

Find a Safe Walk Through a Grid

medium
You are given an m x n binary matrix grid and an integer health.

Find Minimum Time to Reach Last Room I

medium
There is a dungeon with n x m rooms arranged as a grid.

Find Minimum Time to Reach Last Room II

medium
There is a dungeon with n x m rooms arranged as a grid.

Find the City With the Smallest Number of Neighbors at a Threshold Distance

medium
There are n cities numbered from 0 to n-1.

Minimize the Maximum Edge Weight of Graph

medium
You are given two integers, n and threshold, as well as a directed weighted graph of n nodes numbered from 0 to n - 1.

Minimum Cost of a Path With Special Roads

medium
You are given an array start where start = [startX, startY] represents your initial position (startX, startY) in a 2D space.

Minimum Cost to Convert String I

medium
You are given two 0-indexed strings source and target, both of length n and consisting of lowercase English letters.

Minimum Time to Reach Destination in Directed Graph

medium
You are given an integer n and a directed graph with n nodes labeled from 0 to n - 1.

Minimum Time to Visit Disappearing Nodes

medium
There is an undirected graph of n nodes.

Network Delay Time

medium
You are given a network of n nodes, labeled from 1 to n.

Number of Restricted Paths From First to Last Node

medium
There is an undirected weighted connected graph.

Number of Ways to Arrive at Destination

medium
You are in a city that consists of n intersections numbered from 0 to n - 1 with bi-directional roads between some intersections.

Find Edges in Shortest Paths

hard
You are given an undirected weighted graph of n nodes numbered from 0 to n - 1.

Minimum Cost to Convert String II

hard
You are given two 0-indexed strings source and target, both of length n and consisting of lowercase English characters.

Minimum Cost to Make at Least One Valid Path in a Grid

hard
Given an m x n grid.

Minimum Obstacle Removal to Reach Corner

hard
You are given a 0-indexed 2D integer array grid of size m x n.

Minimum Time to Transport All Individuals

hard
You are given n individuals at a base camp who need to cross a river to reach a destination using a single boat.

Minimum Time to Visit a Cell In a Grid

hard
You are given a m x n matrix grid consisting of non-negative integers where grid[row][col] represents the minimum time required to be able to visit the cell (row, col), which...

Minimum Weighted Subgraph With the Required Paths

hard
You are given an integer n denoting the number of nodes of a weighted directed graph.

Modify Graph Edge Weights

hard
You are given an undirected weighted connected graph containing n nodes labeled from 0 to n - 1, and an integer array edges where edges[i] = [ai, bi, wi] indicates that there is...

Network Recovery Pathways

hard
You are given a directed acyclic graph of n nodes numbered from 0 to n − 1.

Number of Possible Sets of Closing Branches

hard
There is a company with n branches across the country, some of which are connected by roads.