1165. Single-Row Keyboard

Problem

Given a keyboard mapping and a word, return the total time to type the word, starting from index 0.

There is a special single-row keyboard where all keys are arranged in a single row. Given a string keyboard that represents the layout of the keyboard (26 lowercase letters), and a string word to type, return the total time required to type the word.

You start at position 0 (the first character of the keyboard). To type a character, you move from your current position to the position of that character on the keyboard. The time taken is the absolute distance between positions.

Examples
Input: ["abcdefghijklmnopqrstuvwxyz","cba"]
Output: 4
Hints
Related Problems

1165. Single-Row Keyboard

Given a keyboard mapping and a word, return the total time to type the word, starting from index 0.