Eight-Direction Keyboard Typing Time
Problem statement
Every character appears once in a rectangular keyboard grid. Typing the first character costs no time. From the current key, each move to any of the eight neighboring cells costs one second.
Return the minimum number of seconds to type word in order.
Function
typingTime(keyboard: String[], word: String) → intExamples
Example 1
keyboard = ["abc","efg","hil"]word = "bfgcil"return = 6Chebyshev distances between consecutive keys sum to six.
Constraints
1 <= keyboard.length, keyboard[r].length <= 100.- Rows have equal length and all keyboard characters are unique.
1 <= word.length <= 100000, and every word character appears on the keyboard.- For this exercise, assume every keyboard and word character is ASCII; each character occupies one grid cell.