Error
|
|
---|---|
@Ibrahim Nash | 6381 |
@blackshadows | 6329 |
@mb1973 | 5388 |
@Quandray | 5231 |
@akhayrutdinov | 5111 |
@saiujwal13083 | 4510 |
@sanjay05 | 3762 |
@marius_valentin_dragoi | 3522 |
@sushant_a | 3459 |
@verma_ji | 3357 |
@KshamaGupta | 3318 |
Complete Leaderboard | |
|
|
@1905439 | 553 |
@terabaap123 | 508 |
@smitadiwedi1991 | 279 |
@DevanandJayakumar | 250 |
@atishagusain | 244 |
@gupta_10 | 226 |
@nipun edara | 224 |
@shubhamkhullar7 | 224 |
@sharmachandan487 | 204 |
@balunagar | 204 |
@arshjit_singh7 | 190 |
Complete Leaderboard |
A top secret message containing letters from A-Z
is being encoded to numbers using the following mapping:
'A' -> 1
'B' -> 2
...
'Z' -> 26
You are an FBI agent. You have to determine the total number of ways that message can be decoded.
Note: An empty digit sequence is considered to have one decoding. It may be assumed that the input contains valid digits from 0 to 9 and If there are leading 0’s, extra trailing 0’s and two or more consecutive 0’s then it is an invalid string.
Example 1:
Input: str = "123"
Output: 3
Explanation: "123" can be decoded as "ABC"(123),
"LC"(12 3) and "AW"(1 23).
Example 2:
Input: str = "27"
Output: 1
Explanation: "27" can be decoded as "BG".
Your Task:
You don't need to read or print anything. Your task is to complete the function CountWays() which takes the string as str as input parameter and returns the total number of ways the string can be decoded modulo 109 + 7.
Expected Time Complexity: O(n)
Expected Space Complexity: O(n) where n = |str|
Constraints:
1 <= |str| <= 104
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes