Skip to content

Practice Minimum Distance to Type a Word Using Two Fingers

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1320
LeetCode Problem

Minimum Distance to Type a Word Using Two Fingers

Problem Statement

The uppercase keyboard has rows ABCDEF, GHIJKL, MNOPQR, STUVWX, and YZ, aligned on the left. Coordinates start at (0, 0), so a letter with zero-based alphabet index q is at (q // 6, q % 6), where // means integer division. Use two fingers to type word in order. Moving a finger from (r1, c1) to (r2, c2) costs |r1 - r2| + |c1 - c2|. Initial finger positions are free and may be chosen independently. Return the minimum total movement distance.

Source: Minimum Distance to Type a Word Using Two Fingers on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
word = "CAKE"
Output
3

# Example 2

Input
word = "HAPPY"
Output
6

Constraints

2 <= word.length <= 300
word consists of uppercase English letters.

Related LeetCode Problems

Practice more problems similar to Minimum Distance to Type a Word Using Two Fingers.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.