Answer: PROGCAP Hiring | Off-Campus OA (2024) | Count Number of Texts
Answer · Posted Jun 2026
Approach Use Dynamic Programming. Let: dp[i] represent the number of ways to decode the first i characters. For every position: Digits 2,3,4,5,6,8 allow at most 3 consecutive presses. Digits 7,9 allow at most 4 consecutive presses. Try grouping the last: 1, 2, 3 (or 4) same digits and add the corresponding previous DP value. Strategy Initialize: dp[0] = 1 Traverse the string. Check up to: 3 identical digits for normal keys 4 identical digits for keys 7 and 9 Add ...
The full answer & interview discussion are available to premium members.
Log in Create a free account