# Letter Case Permutation

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.

```
Examples:
Input:
 S = "a1b2"

Output:
 ["a1b2", "a1B2", "A1b2", "A1B2"]


Input:
 S = "3z4"

Output:
 ["3z4", "3Z4"]


Input:
 S = "12345"

Output:
 ["12345"]
```

## Note

```
Time complexity: O(n*2^l), l = # of letters in the string
Space complexity: O(n) + O(n*2^l)
```

## Code

```
class Solution {
    public List<String> letterCasePermutation(String S) {
        List<String> res = new ArrayList<>();
        helper(res, S.toCharArray(), 0);
        return res;
    }

    private void helper(List<String> res, char[] c, int pos) {
        if (pos == c.length) {  
            res.add(String.valueOf(c));
            return;
        }
        if (Character.isLetter(c[pos])) {
            c[pos] = Character.toLowerCase(c[pos]);
            helper(res, c, pos + 1);
            c[pos] = Character.toUpperCase(c[pos]);
            helper(res, c, pos + 1);
        } else {
            helper(res, c, pos + 1);
        }
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://luj.gitbook.io/code/dfs/enumeration/letter-case-permutation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
