Ctrl K

Most Crowded Digit-Sum Groups

Easy
The numbers from 1 to top are split into groups: two numbers share a group when their digits add up to the same value. For example, 4, 13 and 22 end up together. Find the size of the largest group and return how many groups have exactly that size.
Example 1
top=15 → 6

The groups with digit sums 1 to 6 each hold two numbers (such as 3 and 12, or 6 and 15), while groups 7, 8 and 9 hold one. There are 6 largest groups.

Example 2
top=3 → 3

Three groups of one number each: [1], [2], [3]. All of them are the largest.

Example 3
top=20 → 1

The group with digit sum 2 holds three numbers, 2, 11 and 20, and every other group is smaller. There is one largest group.

Constraints
  • 1 ≤ top ≤ 10⁴
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasyDigit Squares Down to One EasyThe Lost Ticket EasyEven Piles of Cards EasyPairs of Equal Values Easy
loading Python…
Input
top=15
Expected
6

Run checks the first 3 tests in your browser. Submit checks all 48 tests on the server, hidden ones included.