using System.Collections;
static char[] chars = new char[] {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
static ArrayList strList = new ArrayList();
public static void Main()
if(no <= 0) { Console.WriteLine( "Invalid input"); return; }
int[] digits = new int[no.ToString().Length];
StringBuilder sb = new StringBuilder();
getPossibleStrings(digits, 0, sb);
for(int j=0; j<strList.Count; j++) {
Console.WriteLine(strList[j]);
Console.WriteLine("Output : " + strList.Count);
public static void getPossibleStrings(int[] digits, int index, StringBuilder str)
if (index == digits.Length)
var listItem = str.ToString();
if(!strList.Contains(listItem)) {
var isNextDigitZero = index + 1 < digits.Length && digits[index+1] == 0 ? true : false;
str.Append(chars[digits[index] - 1]);
getPossibleStrings(digits, index + 1, str);
str.Remove(str.Length - 1, 1);
getPossibleStrings(digits, index + 1, str);
if (index + 1 < digits.Length)
int sumOfDigits = digits[index] * 10 + digits[index + 1];
if (sumOfDigits > 0 && sumOfDigits <= 26)
str.Append(chars[sumOfDigits - 1]);
getPossibleStrings(digits, index + 2, str);
str.Remove(str.Length - 1, 1);
getPossibleStrings(digits, index + 2, str);