Decoding a Cipher

You are given a secret message (cipher) in the form of an array of integers as an argument. Each individual integer will map to the 26 letters of the English alphabet: 1=A, 2=B, 3=C,...,X=24, Y=25, Z=26. Return the number of ways that the integers could be decoded to letters without rearranging the given order.


  • Must return an integer

Example #1

> 3

  1. 1, 2, 1 could be decoded to "ABA"
  2. 1, 21 could be decoded to "AU"
  3. 12, 1 could be decoded to "LA"
  4. We can "decode" this cipher three different ways, so we return 3.

Example #1

> 1

  1. 6,7,8,9 could be decoded to "FGHI"
  2. We can only "decode" this cipher one way since there aren't 67, 89 or 789 etc characters in the alphabet, so we can't map a letter to these integers.