Given a string you need to print all possible strings that can be made by placing spaces (zero or one) in between them
Input : str = "ABC" Output : ABC AB C A BC A B C Input : str = "ABCD" Output : ABCD A BCD AB CD A B CD ABC D A BC D AB C D A B C D
If we take a closer look, we can notice that this problem boils down to Power Set problem. We basically need to generate all subsets where every element is a different space.
ABC A BC AB C A B C
Asked in: Amazon
This article is contributed by Jebasingh and Ninja.
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Print all possible strings that can be made by placing spaces
- Count number of strings (made of R, G and B) using given combination
- Find the longest string that can be made up of other strings from the array
- Check whether two strings can be made equal by increasing prefixes
- Print all interleavings of given two strings
- Print all pairs of anagrams in a given array of strings
- Print all possible strings of length k that can be formed from a set of n characters
- Print common characters of two Strings in alphabetical order
- Print the final string when minimum value strings get concatenated in every operation
- Print array of strings in sorted order without copying one string into another
- Print all distinct circular strings of length M in lexicographical order
- Python code to print common characters of two Strings in alphabetical order
- Remove spaces from a given string
- Remove extra spaces from a string
- C++ Program to remove spaces from a string