FastPrepEight-Direction Keyboard Typing Time

Eight-Direction Keyboard Typing Time

Benchling logoBenchling● MediumFULLTIMEPHONE SCREEN
Learn

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) → int

Examples

Example 1

keyboard = ["abc","efg","hil"]word = "bfgcil"return = 6

Chebyshev 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.

More Benchling problems

See Benchling hiring insights
public int typingTime(String[] keyboard, String word) {
    // Write your code here.
}
keyboard["abc","efg","hil"]
word"bfgcil"
expected6
Checking account…