Problem Statement:


Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string.

Return a list of all possible strings we could create. You can return the output in any order.

Example 1:
Input: S = "a1b2"
Output: ["a1b2","a1B2","A1b2","A1B2"]

Example 2:
Input: S = "3z4"
Output: ["3z4","3Z4"]

Example 3:
Input: S = "12345"
Output: ["12345"]

Example 4:
Input: S = "0"
Output: ["0"]

Solution:


  • NOTE: I highly recommend going through the Backtracking chapters in the order they are given in the Index Page to get the most out of our content on Backtracking and be able to build a rock-solid understanding.


Solution of this problem provides a great demonstration of how the backtracking template helps us to come up with backtracking solution for a combinatorial problem seamlessly. Before going on to discuss more complex problem I would like you to be super comfortable with the use of the backtracking template and this is the very purpose of this problem.

One more thing I would like to show here is: how the backtracking template helps us to express our thought process without saying a word and just writing code adhering to the template. I would purposefully not write any algorithmic explanation and directly jump on to writing the code. You would still be able to understand my thought process just by looking at the code if you know what each of the methods in our template imply. This makes the code so much more readable, which is a characteristic of clean code.

As you progress in your software engineering career you would start appreciating more and more the importance of knowing the taxonomy well. It makes it so much easier talking to other engineers and even to the business.

Java Code:



Login to Access Content



Python Code:



Login to Access Content




Don't forget to take in-depth look at the other backtracking problems because that is what would get you comfortable with using the backtracking template and master the art of Backtracking:


Instructor:



If you have any feedback, please use this form: https://thealgorists.com/Feedback.



Help Your Friends save 40% on our products

wave