keyIndices
of size 26 to store the index of each letter in the keyboard.keyboard
string and store the index of each character in keyIndices
.result
to 0 to store the total time.prev
to 0 to represent the initial finger position.c
in the word
string.c
, find its index in keyIndices
and calculate the absolute difference with prev
.result
.prev
to the index of c
.result
as the total time required to type the word.