Search
⌘K

Leetcode 2976. Minimum Cost to Convert String I

Given source and target strings and a set of weighted directed character transformations (possibly with multiple edges), find the minimum total cost to turn each source character into the corresponding target character by chaining allowed transforms, or return -1 if any position is unreachable. This reduces to computing shortest-path distances between letters (small fixed alphabet) and summing the per-position costs.

Asked at:

Microsoft

Microsoft


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Early April, 2026

Microsoft

Microsoft

Senior

A string is called a bridge. When a similar character is found, then it can jump to the character with 0 cost; else, it will move by 1 place at a time. The cost of the move is the difference between the two characters

Your account is free and you can post anonymously if you choose.