Telephone Keypad String Encoding
Updated
Problem statement
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) → StringExamples
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 <= 100000textcontains English letters and spaces.textcontains at least one letter.
More Epic Online Assessment questions
Similar questions at other companies
- Branch with the Most FilesCapital One · OACapital One interview questions
- Robot Stops Left or Right (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
- Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
- REST API: Highest International StudentsRippling · OARippling interview questions
- Rearrange String by Alternating EndsHudson River Trading · OAHudson River Trading interview questions
- Filter Isolated Interior Signal BitsSEDEMAC · OA
- Scale Ingredient QuantitiesUpstart · OAUpstart interview questions
- Count Invalid Log GroupsIBM · OAIBM interview questions
- Count Case-Insensitive TripletsTikTok · OATikTok interview questions
- Simulate a Deterministic Finite AutomatonPoint72 · OAPoint72 interview questions