LC: 1165. Single Row Keyboard - spiralgo/algorithms GitHub Wiki
1165. Single-Row Keyboard:
The Essence:
The time taken to move your finger from index i to index j is |i - j|.
It is why the essence of the solution is storing the index of each character (in order to be able to retrieve them in further steps.)
Details:
-
You can use a map kind of data structure. Use the character as a key and the index as a value.
-
You can also use a char array instead of a map, as all the characters on the keyboard are unique.