Minimum Distance to Type a Word on a Keyboard Layout

Day 102: The Two-Finger Typing Grind ⌨️✌️ Problem 1320: Minimum Distance to Type a Word Today’s solve was about minimizing movement on a 6×5 keyboard layout. The Strategy: • Optimization via Savings: Instead of just calculating distance, I used Dynamic Programming to find the maximum "cost saved" by utilizing a second finger. • Efficient DP State: dp[c] tracks the max distance saved with the second finger at character c, allowing me to find the optimal path in a single pass. By focusing on "distance saved" rather than "total cost," the logic becomes much faster and cleaner. Day 102—keep optimizing. 🚀 #LeetCode #Java #DynamicProgramming #Algorithms #DailyCode

  • text

To view or add a comment, sign in

Explore content categories