Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6420
@blackshadows 6380
@mb1973 5642
@Quandray 5233
@akhayrutdinov 5111
@saiujwal13083 4610
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3413
Complete Leaderboard
Spell a Number
Basic Accuracy: 46.54% Submissions: 142 Points: 1

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 = 11112
Output:
8
Explanation:
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| <= 1050

to report an issue on this page.

Editorial

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

Yes

All Submissions

My Submissions:

Login to access your submissions.

Spell a Number

Output Window