<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>

#include <algorithm>
#include <cctype>
// #include <iostream>
#include <string>
#include <vector>

std::vector<std::string> case_combinations(const std::string& text) {
  std::vector<std::string> combos;

  const auto is_digit = [](char ch) {
    return ch >= '0' && ch <= '9';
  };
  const int digits = std::count_if(text.begin(), text.end(), is_digit);
  const int letters = text.size() - digits;
  const int num_combos = 1 << letters;
  // std::cout << '\"' << text << "\" contains " << digits << " digits and " << letters << " letters.\n";
  std::string copy;
  for (int i = 0; i < num_combos; ++i) {
    copy = text;
    int mask = i;
    auto iter = copy.begin();
    for (;;) {
      iter = std::find_if_not(iter, copy.end(), is_digit);
      if (iter == copy.end()) {
        combos.push_back(copy);
        break;
      }
      if (mask & 1) {
        *iter = std::toupper(*iter);
      } else {
        *iter = std::tolower(*iter);
      }
      mask >>= 1;
      ++iter;
    }
  }

  return combos;
}

class Solution {
public:
    std::vector<std::string> letterCasePermutation(const std::string& text) {
        return case_combinations(text);
    }
};

12000