Practice Shift Distance Between Two Strings
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given equally long strings s and t, shift any character of s forward or backward by one alphabet position per operation, wrapping z to a or a to z. If its current alphabet index is j, a forward shift costs nextCost[j] and a backward shift costs previousCost[j]. Return the minimum total cost to transform s into t.
Source: Shift Distance Between Two Strings on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s = "abab", t = "baba", nextCost = [100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], previousCost = [1,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
2
# Example 2
s = "leet", t = "code", nextCost = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], previousCost = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
31
Constraints
Related LeetCode Problems
Practice more problems similar to Shift Distance Between Two Strings.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.