Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Minimum Cost to Convert String I
Bookmark
Dijkstra per Character
Floyd-Warshall
Input
Example 1
Cycle
Repeated
Custom
source
=
abcd
,
target
=
acbe
,
original
=
[a, b, c, c, e, d]
,
changed
=
[b, c, b, e, b, e]
,
cost
=
[2, 5, 5, 1, 2, 20]
Minimum Cost to Convert String
Initializing...
Conversion Cost Matrix
a
b
c
d
e
a
0
∞
∞
∞
∞
b
∞
0
∞
∞
∞
c
∞
∞
0
∞
∞
d
∞
∞
∞
0
∞
e
∞
∞
∞
∞
0
src
a
b
c
d
tgt
a
c
b
e
Total Cost: 0
Minimum Cost to Convert String
Initializing...
Conversion Cost Matrix
a
b
c
d
e
a
0
∞
∞
∞
∞
b
∞
0
∞
∞
∞
c
∞
∞
0
∞
∞
d
∞
∞
∞
0
∞
e
∞
∞
∞
∞
0
src
a
b
c
d
tgt
a
c
b
e
Total Cost: 0
Minimum Cost to Convert String
Initializing...
Conversion Cost Matrix
a
b
c
d
e
a
0
2
∞
∞
∞
b
∞
0
5
∞
∞
c
∞
5
0
∞
1
d
∞
∞
∞
0
20
e
∞
2
∞
∞
0
src
a
b
c
d
tgt
a
c
b
e
Total Cost: 0
Minimum Cost to Convert String
Initializing...
Conversion Cost Matrix
a
b
c
d
e
a
0
2
7
∞
8
b
∞
0
5
∞
∞
c
∞
5
0
∞
1
d
∞
∞
∞
0
20
e
∞
2
∞
∞
0
src
a
b
c
d
tgt
a
c
b
e
Total Cost: 0
Minimum Cost to Convert String
Initializing...
Conversion Cost Matrix
a
b
c
d
e
a
0
2
7
∞
8
b
∞
0
5
∞
6
c
∞
5
0
∞
1
d
∞
∞
∞
0
20
e
∞
2
∞
∞
0
src
a
b
c
d
tgt
a
c
b
e
Total Cost: 0
Minimum Cost to Convert String
Initializing...
Conversion Cost Matrix
a
b
c
d
e
a
0
2
7
∞
8
b
∞
0
5
∞
6
c
∞
5
0
∞
1
d
∞
∞
∞
0
20
e
∞
2
∞
∞
0
src
a
b
c
d
tgt
a
c
b
e
Total Cost: 0
Minimum Cost to Convert String
Initializing...
Conversion Cost Matrix
a
b
c
d
e
a
0
2
7
∞
8
b
∞
0
5
∞
6
c
∞
3
0
∞
1
d
∞
∞
∞
0
20
e
∞
2
∞
∞
0
src
a
b
c
d
tgt
a
c
b
e
Total Cost: 0
Minimum Cost to Convert String
Initializing...
Conversion Cost Matrix
a
b
c
d
e
a
0
2
7
∞
8
b
∞
0
5
∞
6
c
∞
3
0
∞
1
d
∞
22
∞
0
20
e
∞
2
∞
∞
0
src
a
b
c
d
tgt
a
c
b
e
Total Cost: 0
Minimum Cost to Convert String
Initializing...
Conversion Cost Matrix
a
b
c
d
e
a
0
2
7
∞
8
b
∞
0
5
∞
6
c
∞
3
0
∞
1
d
∞
22
27
0
20
e
∞
2
∞
∞
0
src
a
b
c
d
tgt
a
c
b
e
Total Cost: 0
Minimum Cost to Convert String
Initializing...
Conversion Cost Matrix
a
b
c
d
e
a
0
2
7
∞
8
b
∞
0
5
∞
6
c
∞
3
0
∞
1
d
∞
22
27
0
20
e
∞
2
7
∞
0
src
a
b
c
d
tgt
a
c
b
e
Total Cost: 0
Minimum Cost to Convert String
Initializing...
Conversion Cost Matrix
a
b
c
d
e
a
0
2
7
∞
8
b
∞
0
5
∞
6
c
∞
3
0
∞
1
d
∞
22
27
0
20
e
∞
2
7
∞
0
src
a
b
c
d
tgt
a
c
b
e
Total Cost: 28
algo
master
.
io
Step:
Start: Initialize 5x5 distance matrix for characters {a, b, c, d, e} with infinity, diagonal = 0
0 / 110
Input
Example 1
Cycle
Repeated
Custom
source
=
abcd
,
target
=
acbe
,
original
=
[a, b, c, c, e, d]
,
changed
=
[b, c, b, e, b, e]
,
cost
=
[2, 5, 5, 1, 2, 20]
0 / 110
algo
master
.
io
Step:
Start: Initialize 5x5 distance matrix for characters {a, b, c, d, e} with infinity, diagonal = 0