layout: the character layout[i] sits at position i (0-based).
You type with one finger, which starts at position 0. To type a letter, you move the finger to its key; moving from position i to position j takes |i - j| units of time.
Return how long it takes to type the string text.layout='abcdefghijklmnopqrstuvwxyz', text='dad' → 9
The finger moves from 0 to 3 for 'd', back to 0 for 'a', then to 3 again: 3 + 3 + 3 = 9.
layout='zyxwvutsrqponmlkjihgfedcba', text='zzz' → 0
'z' sits at position 0, right under the finger, so no movement is needed.
layout='qwertyuiopasdfghjklzxcvbnm', text='pay' → 15
layout exactly oncetext consists of lowercase English letterslayout='abcdefghijklmnopqrstuvwxyz', text='dad'
9
Run checks the first 3 tests in your browser. Submit checks all 87 tests on the server, hidden ones included.