Paths & Grids Hard
Weighted Graph: Substring Reversal
Each move reverses a substring of at least two UTF-16 units; Dijkstra minimizes the sum of substring lengths.
Trace input
Bounded JSONEdit the lesson input, then build a deterministic source-linked trace.
Source scenarios
Complexity
BestO(S² log S)
AverageO(S² log S)
WorstO(S² log S)
SpaceO(S)
Array state
Follow the active comparisons and writes.
Current operation
Trace stateReady to explore
Source behavior & common mistakes
Find the minimum cost and a matching sequence of intermediate words. This is substring reversal, not single-letter substitution.
- Using a word-ladder graph of one-letter changes.
- Allowing a one-character substring reversal.
- Charging a constant cost instead of the substring length.
Algorithm code
JavaWordTransformationSP.javaStep linked
The highlighted line follows the current step.
Ready to begin
Press Play to see what happens.
Detailed execution
Snapshot 1 / 1