<p>Given a string <code>s</code>, you&nbsp;can transform every letter individually to be lowercase or uppercase to create another string.</p>

<p>Return <em>a list of all possible strings we could create</em>. Return the output in <strong>any order</strong>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;a1b2&quot;
<strong>Output:</strong> [&quot;a1b2&quot;,&quot;a1B2&quot;,&quot;A1b2&quot;,&quot;A1B2&quot;]
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;3z4&quot;
<strong>Output:</strong> [&quot;3z4&quot;,&quot;3Z4&quot;]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 12</code></li>
	<li><code>s</code> consists of lowercase English letters, uppercase English letters, and digits.</li>
</ul>

class Solution {
public:
    vector<string> letterCasePermutation(string s) {
        vector<string> ans;
        vector<int> letterIndices; // To store positions of letters
        int letterCount = 0;

        // Step 1: Count letters and store their positions
        for (int i = 0; i < s.size(); i++) {
            if (isalpha(s[i])) {  // Check if it's a letter
                letterCount++;
                letterIndices.push_back(i);
            }
        }

        // Step 2: Generate all 2^letterCount combinations using bit manipulation
        int combinations = 1 << letterCount; // 2^letterCount
        for (int mask = 0; mask < combinations; mask++) {
            string modified = s; // Copy original string

            // For each letter, decide whether to make it uppercase or lowercase
            for (int j = 0; j < letterCount; j++) {
                int letterIndex = letterIndices[j];
                
                if (mask & (1 << j)) {
                    // If the bit is set, convert to uppercase
                    modified[letterIndex] = toupper(modified[letterIndex]);
                } else {
                    // If the bit is not set, convert to lowercase
                    modified[letterIndex] = tolower(modified[letterIndex]);
                }
            }

            // Add the modified string to the result
            ans.push_back(modified);
        }

        return ans;
    }
};
11800