Description
Given a string keyboard of 26 unique lowercase English letters and a string word, return the total distance to type word if you only use one finger.
Examples
Input:
keyboard = "abcdefghijklmnopqrstuvwxyz", word = "cba"Output:
4Explanation:
c(2)+b(1)+a(1)=4.
Input:
keyboard = "qwertyuiopasdfghjklzxcvbnm", word = "hello"Output:
54Explanation:
Keyboard positions: h=15, e=2, l=18, o=8. Movement: 0->15 (15), 15->2 (13), 2->18 (16), 18->18 (0), 18->8 (10). Total = 15+13+16+0+10 = 54.
Input:
keyboard = "abcdefghijklmnopqrstuvwxyz", word = "dad"Output:
9Explanation:
Alphabetical keyboard: d=3, a=0. Movement: 0->3 (3), 3->0 (3), 0->3 (3). Total = 3+3+3 = 9.
Constraints
- •
keyboard.length == 26