<p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>

<ul>
	<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
	<li>It consists of only one unique digit.</li>
</ul>

<p>Return <em>the <strong>maximum good </strong>integer as a <strong>string</strong> or an empty string </em><code>&quot;&quot;</code><em> if no such integer exists</em>.</p>

<p>Note:</p>

<ul>
	<li>A <strong>substring</strong> is a contiguous sequence of characters within a string.</li>
	<li>There may be <strong>leading zeroes</strong> in <code>num</code> or a good integer.</li>
</ul>

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

<pre>
<strong>Input:</strong> num = &quot;6<strong><u>777</u></strong>133339&quot;
<strong>Output:</strong> &quot;777&quot;
<strong>Explanation:</strong> There are two distinct good integers: &quot;777&quot; and &quot;333&quot;.
&quot;777&quot; is the largest, so we return &quot;777&quot;.
</pre>

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

<pre>
<strong>Input:</strong> num = &quot;23<strong><u>000</u></strong>19&quot;
<strong>Output:</strong> &quot;000&quot;
<strong>Explanation:</strong> &quot;000&quot; is the only good integer.
</pre>

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

<pre>
<strong>Input:</strong> num = &quot;42352338&quot;
<strong>Output:</strong> &quot;&quot;
<strong>Explanation:</strong> No substring of length 3 consists of only one unique digit. Therefore, there are no good integers.
</pre>

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

<ul>
	<li><code>3 &lt;= num.length &lt;= 1000</code></li>
	<li><code>num</code> only consists of digits.</li>
</ul>

class Solution {
public:
    string largestGoodInteger(string num) {

         int ans = -1; // to store what chars merge into
        string strAns = ""; // to store the value to return
        for (int i = 2; i < num.size(); ++i) { // go through from the third
            if (num[i] == num[i - 1] && num[i] == num[i - 2]) { // if current char is equal to the two previous ones
                string sub = num.substr(i - 2, 3); // take the string of this three chars
                int cur = stoi(sub); // convert this string of three chars to int
                if (cur > ans) { // if this int is greater than the answer - change the answer
                    ans = cur;
                    strAns = sub;
                }
            }
        }
        return strAns;
    }
};

/*
    check if the previous and current are equal and also chcek if current and next are equal 
    if it found then return the substrof size 3

    Input
num =
"3200014888"
Output
"000"
Expected
"888" this case will be failed beacuse it will be return the max value inorder to avoid the problem will store in the result variable and then we will return the string





*/
9800