class Solution:
    def calculateTime(self, keyboard: str, word: str) -> int:
        """tc O(N) N: len(word)  sc O(1) 
        main idea: record the index for each character from the keyboard.
        begin point is idx = 0, loop through the word, get each char's index, add the absolute diff from previous finger's position and current char's position to result 
        get final result 
        """
        char2idx = {ch: i for i, c in enumerate(keyboard) }
        res = pre = 0
        for ch in word:
            cur_idx = char2idx[ch]
            res += abs(cur_idx - pre)
            pre = cur_idx
        return res