Free written solution

Minimum Cost to Convert String I (LeetCode 2976): Solution and Explanation

Each rule changes one letter into another for a price. Find the cheapest way to turn source into target position by position, or return -1. Because conversions can chain through other letters, this is an all-pairs shortest path problem on a graph with only 26 nodes.

Read the intuition, approach, code and complexity →