Telephone Keypad String Encoding
Reported by candidates from Epic's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Epic reported this one in September 2026, and it's less scary than the title sounds. Strip the keypad story away and it's a lookup table plus one comparison against the previous key. If you've got an Epic OA coming in a day or two, this is the kind of problem where the whole game is not fumbling the details. It's a string problem with a hash map flavor, nothing more. The traps are the separator rule and the spaces. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but this one is very doable on your own.
The problem
Encode text using a traditional telephone keypad. Letters on keys 2 through 9 require one through four presses according to their position on the key. Ignore spaces and treat uppercase and lowercase letters identically. If two consecutive encoded letters use the same key, insert # between their digit sequences. Return the complete encoded string. Function encodeKeypad(text: String) → String Examples Example 1 text = "AB" return = "2#22" A and B share key 2, so a separator is inserted. Example 2 text = "HEY EPIC" return = "4433999337444222" The space is ignored and no adjacent encoded letters share a keypad key. Constraints 1 <= text.length <= 100000 text contains English letters and spaces. text contains at least one letter.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: map each letter to its key digit and its press count, then build the output by walking the string once. Lowercase everything first, skip spaces, and track the last key you emitted. If the current letter's key equals the last key, append # before the digits. Then set last key to the current one. The common pitfall is resetting the previous key when you hit a space. Don't. The spec says spaces are ignored, so 'A B' has A and B adjacent and needs the separator. Example 1 shows this: AB gives 2#22. Another pitfall is string concatenation in a loop. With up to 100000 characters, use a list or StringBuilder and join at the end. Remember the keypad: 7 (PQRS) and 9 (WXYZ) have four letters, the rest have three. If you blank on the table layout during the live OA, StealthCoder can cover you, but the logic is just one pass and O(n).
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Telephone Keypad String Encoding cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Epic's OA.
Epic reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Telephone Keypad String Encoding FAQ
How hard is the Epic keypad encoding problem really?+
Easy. It's a single pass over the string with a lookup table. There's no clever algorithm. The difficulty is in the details: ignoring spaces, case-insensitivity, and inserting the # separator only when consecutive letters share a key.
What's the trick to the separator rule?+
Keep a variable for the last key you emitted. Before writing a letter's digits, compare its key to that variable. If they match, write # first. Update the variable after each letter. Never reset it on spaces, since spaces are skipped entirely.
Do spaces break the adjacency check?+
No. Spaces are ignored, so two letters with a space between them count as consecutive encoded letters. 'A B' should produce 2#22. Only track the previous letter's key, not the previous character in the raw input.
How should I build the lookup table?+
Hardcode the groups: 2 ABC, 3 DEF, 4 GHI, 5 JKL, 6 MNO, 7 PQRS, 8 TUV, 9 WXYZ. For each letter, the digit is its key and the press count is its index in the group plus one. Repeat the digit that many times.
How do I prepare for this in 48 hours?+
Write it once from scratch with the table and test both examples, then try 'A B' and mixed case. Make sure you use a list or builder for output since input can hit 100000 characters. Twenty minutes is enough for this pattern.