Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
The problem can be approached greedily.
For each index in order from <code>0</code> to <code>n - 1</code>, we try all letters from <code>'a'</code> to <code>'z'</code>, selecting the first one as long as the current total distance accumulated is not larger than <code>k</code>.