<p>A binary watch has 4 LEDs on the top to represent the hours (0-11), and 6 LEDs on the bottom to represent&nbsp;the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right.</p>

<ul>
	<li>For example, the below binary watch reads <code>&quot;4:51&quot;</code>.</li>
</ul>

<p><img alt="" src="https://assets.leetcode.com/uploads/2021/04/08/binarywatch.jpg" style="width: 500px; height: 500px;" /></p>

<p>Given an integer <code>turnedOn</code> which represents the number of LEDs that are currently on (ignoring the PM), return <em>all possible times the watch could represent</em>. You may return the answer in <strong>any order</strong>.</p>

<p>The hour must not contain a leading zero.</p>

<ul>
	<li>For example, <code>&quot;01:00&quot;</code> is not valid. It should be <code>&quot;1:00&quot;</code>.</li>
</ul>

<p>The minute must&nbsp;consist of two digits and may contain a leading zero.</p>

<ul>
	<li>For example, <code>&quot;10:2&quot;</code> is not valid. It should be <code>&quot;10:02&quot;</code>.</li>
</ul>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> turnedOn = 1
<strong>Output:</strong> ["0:01","0:02","0:04","0:08","0:16","0:32","1:00","2:00","4:00","8:00"]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> turnedOn = 9
<strong>Output:</strong> []
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>0 &lt;= turnedOn &lt;= 10</code></li>
</ul>

class Solution {
public:

    void getNVec(vector<int>& checkNum, int startIdx, vector<string>& outputVec, int remainCnt, int maxNum, int currentNum, bool addLeadingzero) {
        //cout << "=====getNVec=======" << endl;
        if (remainCnt == 1) {
            //cout << "currentNum = " << currentNum << endl;
            //cout << "startIdx = " << startIdx << endl;
            for (int idx=startIdx; idx < checkNum.size(); idx++) {
                if (currentNum+checkNum[idx] >= maxNum) {
                    continue;
                }
                //cout << "  pushing val currentNum = " << currentNum + checkNum[idx] << endl;
                if (addLeadingzero && currentNum + checkNum[idx] < 10) {
                    string s = "0";
                    outputVec.push_back(s + to_string(currentNum + checkNum[idx]));
                }
                else {
                    outputVec.push_back(to_string(currentNum + checkNum[idx]));
                }
            }
        }
        else {
            for (int idx=startIdx; idx < checkNum.size()-1; idx++) {
                //cout << "checking startIdx " << idx << endl;
                if (currentNum+checkNum[idx] >= maxNum) {
                    continue;
                }
                getNVec(checkNum, idx+1, outputVec, remainCnt-1, maxNum, currentNum+checkNum[idx], addLeadingzero);
            }
        }
        //cout << "=====getNVec end=======" << endl;
    }
    vector<string> readBinaryWatch(int turnedOn) {
        //unordered_map<int, vector<string>> hourMap;
        unordered_map<int, vector<string>> minuteMap;
        vector<string> minuteOutpurVec;
        vector<string> result;

        // minutes
        vector<int> minuteVec = {32,16,8,4,2,1};
        minuteOutpurVec.push_back("00");
        sort(minuteOutpurVec.begin(), minuteOutpurVec.end());
        minuteMap.insert(make_pair(0, minuteOutpurVec));

        minuteOutpurVec.clear();
        getNVec(minuteVec, 0, minuteOutpurVec, 1, 60, 0, true);
        minuteMap.insert(make_pair(1, minuteOutpurVec));

    
        minuteOutpurVec.clear();
        getNVec(minuteVec, 0, minuteOutpurVec, 2, 60, 0, true);
        minuteMap.insert(make_pair(2, minuteOutpurVec));
        
        minuteOutpurVec.clear();
        getNVec(minuteVec, 0, minuteOutpurVec, 3, 60, 0, true);
        minuteMap.insert(make_pair(3, minuteOutpurVec));
        
        minuteOutpurVec.clear();
        getNVec(minuteVec, 0, minuteOutpurVec, 4, 60, 0, true);
        minuteMap.insert(make_pair(4, minuteOutpurVec));
        
        minuteOutpurVec.clear();
        getNVec(minuteVec, 0, minuteOutpurVec, 5, 60, 0, true);
        /*
        cout << "===== min 5 =====" << endl;
        for(const auto& min:minuteOutpurVec) {
            cout << "  " << min << endl;
        }
        cout << "===== min 5 =====" << endl;
        sort(minuteOutpurVec.begin(), minuteOutpurVec.end());
        */
        minuteMap.insert(make_pair(5, minuteOutpurVec));


        // hour
        vector<int> hourVec = {1,2,4,8};
        vector<string> hourOutpurVec;
        hourOutpurVec.push_back("0");
        //hourMap.insert(make_pair(0, hourOutpurVec));
        auto it = minuteMap.find(turnedOn);
        if (it != minuteMap.end()) {
            for(const auto minute : it->second) {
                for(const auto hour : hourOutpurVec) {
                    result.push_back(hour+":"+minute);
                }
            }
        }
        
        hourOutpurVec.clear();
        getNVec(hourVec, 0, hourOutpurVec, 1, 12, 0, false);
        //hourMap.insert(make_pair(1, hourOutpurVec));
        it = minuteMap.find(turnedOn-1);
        if (it != minuteMap.end()) {
            for(const auto minute : it->second) {
                for(const auto hour : hourOutpurVec) {
                    result.push_back(hour+":"+minute);
                }
            }
        }
        
        hourOutpurVec.clear();
        getNVec(hourVec, 0, hourOutpurVec, 2, 12, 0, false);
        //hourMap.insert(make_pair(2, hourOutpurVec));
        it = minuteMap.find(turnedOn-2);
        if (it != minuteMap.end()) {
            for(const auto minute : it->second) {
                for(const auto hour : hourOutpurVec) {
                    result.push_back(hour+":"+minute);
                }
            }
        }

        hourOutpurVec.clear();
        getNVec(hourVec, 0, hourOutpurVec, 3, 12, 0, false);
        //hourMap.insert(make_pair(3, hourOutpurVec));
        it = minuteMap.find(turnedOn-3);
        if (it != minuteMap.end()) {
            for(const auto minute : it->second) {
                for(const auto hour : hourOutpurVec) {
                    result.push_back(hour+":"+minute);
                }
            }
        }
        



        return result;
    }
};
9600