|
| 1 | +# 2266. Count Number of Texts |
| 2 | + |
| 3 | +Alice is texting Bob using her phone. The mapping of digits to letters is shown in the figure below. |
| 4 | + |
| 5 | +[Image](1200px-telephone-keypad2svg.png) |
| 6 | + |
| 7 | +In order to add a letter, Alice has to press the key of the corresponding digit i times, where i is the position of the |
| 8 | +letter in the key. |
| 9 | + |
| 10 | +- For example, to add the letter `'s'`, Alice has to press `'7'` four times. Similarly, to add the letter `'k'`, Alice |
| 11 | + has to press `'5'` twice. |
| 12 | +- Note that the digits `'0'` and `'1'` do not map to any letters, so Alice does not use them. |
| 13 | + |
| 14 | +However, due to an error in transmission, Bob did not receive Alice's text message but received a string of pressed keys |
| 15 | +instead. |
| 16 | + |
| 17 | +- For example, when Alice sent the message `"bob"`, Bob received the string `"2266622"`. |
| 18 | + |
| 19 | +Given a string `pressedKeys` representing the string received by Bob, return the total number of possible text messages |
| 20 | +Alice could have sent. |
| 21 | + |
| 22 | +Since the answer may be very large, return it modulo `10^9 + 7`. |
| 23 | + |
| 24 | +Example 1: |
| 25 | + |
| 26 | +Input: pressedKeys = "22233" |
| 27 | +Output: 8 |
| 28 | +Explanation: |
| 29 | +The possible text messages Alice could have sent are: |
| 30 | +"aaadd", "abdd", "badd", "cdd", "aaae", "abe", "bae", and "ce". |
| 31 | +Since there are 8 possible messages, we return 8. |
| 32 | + |
| 33 | +Example 2: |
| 34 | + |
| 35 | +Input: pressedKeys = "222222222222222222222222222222222222" |
| 36 | +Output: 82876089 |
| 37 | +Explanation: |
| 38 | +There are 2082876103 possible text messages Alice could have sent. |
| 39 | +Since we need to return the answer modulo 109 + 7, we return 2082876103 % (109 + 7) = 82876089. |
| 40 | + |
| 41 | +Constraints: |
| 42 | + |
| 43 | +- `1 <= pressedKeys.length <= 10^5` |
| 44 | +- `pressedKeys` only consists of digits from `'2'` - `'9'`. |
0 commit comments