Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Generate All Strings
MEDIUM
25 mins
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
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.

Generate All Strings

Contributed by
Amit Shaw
Medium
yellow-spark
0/80
Avg time to solve 25 mins
Success Rate 52 %
Share
0 upvotes

Problem Statement

You are given a string ‘S’ of length ‘N’ which consists of digits from 0 to 9 only. If the mapping of characters from a to z is like a = 1, b = 2, c = 3…. Z = 26. You need to convert the given string of digits into the string of characters using the mapping.

Example:
‘S’ = “112”. 

Output: [aab, al, kb]

The possible ways to convert the given strings is: 
aab => a = 1, a = 1, b = 2,
al => a = 1, l = 12
kb => k = 11, b = 2
Hence, the final array is: [aab, al, kb].
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1 :
2
1123
125
Sample Output 1 :
aabc aaw alc kbc kw
abe ay le
Explanation Of Sample Input 1 :
For the first case:
aabc => a=1, a=1, b=2, c=3
aaw => a=1, a=1, w=23
alc => a=1, l=12, c=3
kbc => k=11, b=2, c=3
kw => k=11, w=23
Sorting the strings in lexicographical order, so the final output is [aabc, aaw, alc, kbc, kw].

For the second case:
abe => a=1, b=2, e=5
le => l=12, e=5
Sorting the strings in lexicographical order, the final output is [abe le].
Sample Input 2 :
2
721023
871121
Sample Output 2 :
gbjbc gbjw 
hgaaba hgaau hgala hgkba hgku
Reset Code
Full screen
Auto
copy-code
Console