20. Make Strings Equal
β GFG solution to Make Strings Equal problem: find minimum cost to transform two strings to be identical using Floyd-Warshall algorithm for shortest path computation. π
π§© Problem Description
π Examples
Example 1
Input: s = "abcc", t = "bccc", transform[][] = [['a', 'b'], ['b', 'c'], ['c', 'a']], cost[] = [2, 1, 4]
Output: 3
Explanation: We can convert both strings into "bccc" with a cost of 3:
- Position 0 in s: a -> b (cost 2)
- Position 1 in s: b -> c (cost 1)
Other characters already match.Example 2
Input: s = "az", t = "dc", transform[][] = [['a', 'b'], ['b', 'c'], ['c', 'd'], ['a', 'd'], ['z', 'c']], cost[] = [5, 3, 2, 50, 10]
Output: 20
Explanation: We can convert both strings into "dc" with a cost of 20:
- Position 0 in s: a -> d by path a->b->c->d (cost 5+3+2=10)
- Position 1 in s: z -> c (cost 10)Example 3
π Constraints
β
My Approach
Floyd-Warshall with Graph Transformation
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated