3361. Shift Distance Between Two Strings
You are given two strings
sandtof the same length, and two integer arraysnextCostandpreviousCost.In one operation, you can pick any index
iofs, and perform either one of the following actions:
- Shift
s[i]to the next letter in the alphabet. Ifs[i] == 'z', you should replace it with'a'. This operation costsnextCost[j]wherejis the index ofs[i]in the alphabet.- Shift
s[i]to the previous letter in the alphabet. Ifs[i] == 'a', you should replace it with'z'. This operation costspreviousCost[j]wherejis the index ofs[i]in the alphabet.The shift distance is the minimum total cost of operations required to transform
sintot.Return the shift distance from
stot.
1 | class Solution { |