<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:
    def countLargestGroup(self, n: int) -> int:
        # Initialize a frequency array where index represents the sum of digits
        frequency = [0] * 37  # Maximum sum of digits for n=10^4 is 36
        
        # Iterate through each number from 1 to n
        for num in range(1, n + 1):
            # Calculate the sum of digits
            sum_digits = 0
            temp = num
            while temp > 0:
                sum_digits += temp % 10  # Add the last digit to sum_digits
                temp = temp // 10        # Remove the last digit
            
            # Increment the frequency for this sum
            frequency[sum_digits] += 1
        
        # Find the maximum frequency among all digit sums
        max_freq = max(frequency)
        
        # Count how many sums have the maximum frequency
        return frequency.count(max_freq)

16700