Time to Type a String

Asked at Google · Coding & Leetcode-style Questions · Difficulty: Easy

Imagine you have a special keyboard with all keys in a single row. The layout of characters on a keyboard is denoted by a string `keyboard` of length 26. Initially your finger is at index 0. To type a character, you have to move your finger to the index of the desired character. The time taken to move your finger from index i to index j is `abs(j - i)`.

Loading the problem…