3
string convertCombination(int *c, int k) {7
for (int i = 0; i < k; i++) {8
int indicatorIdx = c[i];9
switch (indicatorIdx) {54
if (hours > 11 || minutes > 59) return ""; // invalid time55
return (to_string(hours) + ":" + to_string(minutes / 10) + to_string(minutes % 10));58
vector<string> readBinaryWatch(int turnedOn) {59
vector<string> result;64
std::iota(begin(c), begin(c) + k, 0);69
string str = convertCombination(c, k);70
if (!str.empty()) result.push_back(str);73
// go to the next combination74
int alter_idx = 0; // count from the right digit75
while (alter_idx < k && c[k - alter_idx - 1] == (N - 1 - alter_idx)) alter_idx++;76
if (alter_idx == k) break;77
c[k - alter_idx - 1]++;78
for (int i = 0; i < alter_idx; i++) c[k - alter_idx + i] = c[k - alter_idx - 1] + 1 + i;79
str = convertCombination(c, k);80
if (!str.empty()) result.push_back(str);86
void print(int *c, int k, string s) {87
if (s.empty()) return;88
for (int i = 0; i < k; i++) cout << c[i];89
cout << " : " << s << endl;