Print all permutations of a string keeping the sequence but changing cases.
Input : ab Output : AB Ab ab aB Input : ABC Output : abc Abc aBc ABc abC AbC aBC ABC
Method 1 (Naive) : Naive approach would be to traverse the whole string and for every character, consider two cases, (1) change case and recur (2) Do not change case and recur.
Method 2 (Better) For a string of length n there exists 2n maximum combinations. We can represent this as a bitwise operation.
The same idea is discussed in Print all subsequences.
Below is the implementation of above idea :
abc Abc aBc ABc abC AbC aBC ABC
Asked in : Facebook.
This article is contributed by Rohit Thapliyal. 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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Convert the string into palindrome string by changing only one character.
- String in Switch Case in Java
- Convert characters of a string to opposite case
- Toggle case of a string using Bitwise Operators
- Sentence Case of a given Camel cased string
- Extract and print words separately from a given Camel Case string
- Lower case to upper case - An interesting fact
- Case conversion (Lower to Upper and Vice Versa) of a string using BitWise operators in C/C++
- Minimize difference after changing all odd elements to even
- Minimize the number by changing at most K digits
- Make largest palindrome by changing at most K-digits
- Removing a number from array without changing its arithmetic mean
- Find the minimum number possible by changing at most one digit
- Check if a number is power of k using base changing method
- Find the largest number that can be formed by changing at most K digits
- Make the list non-decreasing by changing only one digit of the elements
- Arrangement of words without changing the relative position of vowel and consonants
- Number of steps to sort the array by changing order of three elements in each step
- Camel case of a given sentence
- gOOGLE cASE of a given sentence