Tap here to switch tabs
Problem
Submissions

Problem: Single-Row Keyboard

med
30 min
Try to solve the Single-Row Keyboard problem.

Statement

There is a special single row keyboard layout represented by a string keyboard of length 2626, indexed from 00 to 2525. Initially, your finger is placed at index 00. To type a character, you must move your finger to the index corresponding to that character on the keyboard. The time taken to move your finger from index ii to index jj is ∣i−j∣|i - j|.

Given the string keyboard and a string word, return the total time taken to type all characters of word sequentially.

Constraints:

  • keyboard.length =26= 26

  • keyboard contains each English lowercase letter exactly once in some order.

  • 1≤1 \leq word.length ≤104\leq 10^4

  • word[i] is an English lowercase letter.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Single-Row Keyboard

med
30 min
Try to solve the Single-Row Keyboard problem.

Statement

There is a special single row keyboard layout represented by a string keyboard of length 2626, indexed from 00 to 2525. Initially, your finger is placed at index 00. To type a character, you must move your finger to the index corresponding to that character on the keyboard. The time taken to move your finger from index ii to index jj is ∣i−j∣|i - j|.

Given the string keyboard and a string word, return the total time taken to type all characters of word sequentially.

Constraints:

  • keyboard.length =26= 26

  • keyboard contains each English lowercase letter exactly once in some order.

  • 1≤1 \leq word.length ≤104\leq 10^4

  • word[i] is an English lowercase letter.