Find the Sequence of Strings Appeared on the Screen - Problem
You are given a string target. Alice is going to type target on her computer using a special keyboard that has only two keys:
- Key 1 appends the character "a" to the string on the screen.
- Key 2 changes the last character of the string on the screen to its next character in the English alphabet. For example, "c" changes to "d" and "z" changes to "a".
Note that initially there is an empty string "" on the screen, so she can only press Key 1 first.
Return a list of all strings that appear on the screen as Alice types target, in the order they appear, using the minimum key presses.
Input & Output
Example 1 — Basic Case
$
Input:
target = "abc"
›
Output:
["a","ab","aba","abb","abc"]
💡 Note:
Start empty → add 'a' → add 'a' to get 'aa' then cycle to 'ab' → add 'a' to get 'aba', cycle to 'abb', then 'abc'
Example 2 — Single Character
$
Input:
target = "a"
›
Output:
["a"]
💡 Note:
Only need to add 'a' once, no cycling required
Example 3 — Cycling Required
$
Input:
target = "za"
›
Output:
["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","za"]
💡 Note:
First position cycles through entire alphabet to reach 'z', then add 'a'
Constraints
- 1 ≤ target.length ≤ 1000
- target consists of lowercase English letters only
Visualization
Tap to expand
Understanding the Visualization
1
Input
Target string 'bc' to be typed
2
Process
Use Key 1 (add 'a') and Key 2 (cycle alphabet) to build string
3
Output
All intermediate strings in order
Key Takeaway
🎯 Key Insight: Simulate the exact typing process by extending with 'a' then cycling to target character
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code