Geeksforgeeks

Error

Given a number **N **such that it may contain many continuous digits. Find the number of ways to spell the number.

For example, consider 8884441100, one can spell it simply as triple eight triple four double two and double zero. One can also spell as double eight, eight, four, double four, two, two, double zero.

**Example 1:**

**Input:**
**N** **=** 100
**Output:**
2
**Explanation:**
The number 100 has only 2 possibilities,
1) one zero zero
2) one double zero.

**Example 2:**

Input:N=11112Output:8Explanation:1 1 1 1 2, 11 1 1 2, 1 1 11 2, 1 11 1 2, 11 11 2, 1 111 2, 111 1 2, 1111 2

**Example 3:**

**Input:**
**N** **=** 12345
**Output:**
1
**Explanation:**
The number 12345 has only 1 possibility,
one two three four five

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **differentWaysToSpell()** which takes a **String N **as input and returns the number of possible ways.

**Expected Time Complexity:** O(|N|)

**Expected Auxiliary Space:** O(1)

**Constraints:**

1 <= |N| <= 10^{50}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Spell a Number

...