Close
Topic list
DECODE STRING
MEDIUM
30 mins
Dynamic Programming
Topics (Covered in this problem)
Problem solved
Skill meter
Dynamic Programming
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

DECODE STRING

Contributed by
Abhishek Gupta
Medium
0/80
Avg time to solve 30 mins
Success Rate 50 %
Share

Problem Statement

A message containing letters from A-Z can be encoded into numbers using the following mapping:

``````'A' -> "1"
'B' -> "2"
...
'Z' -> "26"
``````

Given a string ‘S’ containing only digits, return the number of ways to decode it.

Example:
``````Input: ‘S’ = "11106"

Output: 2

The possible ways are:-
(1 1 10 6),
(11 10 6)

Note that the grouping (1 11 06) is invalid because "06" cannot be mapped into 'F' since "6" is different from "06".
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1 :
``````2
12
226
``````
Sample Output 1 :
``````2
3
``````
Explanation Of Sample Input 1 :
``````For the first test case:-
"12" could be decoded as "AB" (1 2) or "L" (12).

For the second test case:-
"226" could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).
``````
Sample Input 2 :
``````2
1234
333
``````
Sample Output 2 :
``````3
1
``````
Auto
Console