Loading
Loading
An old pager sends text by replacing each letter with its position in the alphabet, A = 1 up to Z = 26, and then running the numbers together with no separators. A message like 1226 is ambiguous: it could be several different words.
Given the digit string, return how many different letter sequences it could stand for. A piece that starts with 0 (such as 0 or 06) is never a letter, and neither is any number above 26.
digits = "1226""1": 1 readingA"12": 2 readingsA B, L"122": 3 readingsadd 2 alone (2) + add 22 (1)"1226": 3 + 2 = 56 alone after any of 3, or 26 after any of 25Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
1 2 2 6, 12 2 6, 1 22 6, 1 2 26 and 12 26.
Example 2
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
30 is not a letter and 0 cannot stand alone, so nothing decodes.