<p>You are given an integer <code>n</code>.</p>

<p>Each number from <code>1</code> to <code>n</code> is grouped according to the sum of its digits.</p>

<p>Return <em>the number of groups that have the largest size</em>.</p>

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

<pre>
<strong>Input:</strong> n = 13
<strong>Output:</strong> 4
<strong>Explanation:</strong> There are 9 groups in total, they are grouped according sum of its digits of numbers from 1 to 13:
[1,10], [2,11], [3,12], [4,13], [5], [6], [7], [8], [9].
There are 4 groups with largest size.
</pre>

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

<pre>
<strong>Input:</strong> n = 2
<strong>Output:</strong> 2
<strong>Explanation:</strong> There are 2 groups [1], [2] of size 1.
</pre>

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

<ul>
	<li><code>1 &lt;= n &lt;= 10<sup>4</sup></code></li>
</ul>

class Solution {
public:
    int countLargestGroup(int n) {
        ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

        int *arr = new int[40];
        fill(arr, arr + 40, 0);

        int tmp = -1;

        for (int i = 1; i <= n; i++)
        {
            int t = calcSum(i);
            arr[t]++;
            tmp = max(tmp, arr[t]);
        }

        int ans = 0;

        for (int i = 0; i < 40; i++)
            ans += arr[i] == tmp ? 1 : 0;

        return ans;
    }

    int calcSum(int x)
    {
        int ans = 0;

        while (x)
        {
            ans += x % 10;
            x /= 10;
        }

        return ans;
    }
};
7700