Tap here to switch tabs
Problem
Submissions

Problem: Count Number of Texts

med
30 min
Try to solve the Count Number of Texts problem.

Statement

Alice is typing a text message on a classic mobile phone keypad. Each digit from '2' to '9' is mapped to a specific set of lowercase English letters:

  • '2' maps to 'a', 'b', 'c'

  • '3' maps to 'd', 'e', 'f'

  • '4' maps to 'g', 'h', 'i'

  • '5' maps to 'j', 'k', 'l'

  • '6' maps to 'm', 'n', 'o'

  • '7' maps to 'p', 'q', 'r', 's'

  • '8' maps to 't', 'u', 'v'

  • '9' maps to 'w', 'x', 'y', 'z'

To type a character, a button is pressed consecutively between 11 and 33 times for keys mapping to 33 letters, or between 11 and 44 times for keys mapping to 44 letters.

Given a string pressedKeys representing the sequence of button presses, return the total number of possible text messages Alice could have sent.

Since the result can be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq pressedKeys.length ≤105\leq 10^5

  • pressedKeys only consists of digits from '2' to '9'

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Number of Texts

med
30 min
Try to solve the Count Number of Texts problem.

Statement

Alice is typing a text message on a classic mobile phone keypad. Each digit from '2' to '9' is mapped to a specific set of lowercase English letters:

  • '2' maps to 'a', 'b', 'c'

  • '3' maps to 'd', 'e', 'f'

  • '4' maps to 'g', 'h', 'i'

  • '5' maps to 'j', 'k', 'l'

  • '6' maps to 'm', 'n', 'o'

  • '7' maps to 'p', 'q', 'r', 's'

  • '8' maps to 't', 'u', 'v'

  • '9' maps to 'w', 'x', 'y', 'z'

To type a character, a button is pressed consecutively between 11 and 33 times for keys mapping to 33 letters, or between 11 and 44 times for keys mapping to 44 letters.

Given a string pressedKeys representing the sequence of button presses, return the total number of possible text messages Alice could have sent.

Since the result can be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq pressedKeys.length ≤105\leq 10^5

  • pressedKeys only consists of digits from '2' to '9'