A robotics fulfillment center numbers its delivery robots sequentially from 1 to n as they roll off the assembly line. Every robot is routed to a charging dock whose number equals the sum of the decimal digits of the robot's own number (for example, robot 132 is routed to dock 6, since 1 + 3 + 2 = 6). After all n robots have been assigned to a dock, the floor manager wants to know how many distinct docks ended up hosting the largest number of robots -- that is, how many docks are tied for the maximum occupancy.
A single line containing one integer n.
A single integer: the number of docks that are tied for holding the maximum number of robots.
Example 1
Input
13
Expected
4
Explanation
Robots 1 through 9 form their own single-member digit-sum groups (docks 1 through 9). Robot 10 (digit sum 1) joins robot 1's dock, robot 11 (digit sum 2) joins robot 2's dock, robot 12 (digit sum 3) joins robot 3's dock, and robot 13 (digit sum 4) joins robot 4's dock. Docks 1, 2, 3, and 4 each now host 2 robots, the largest occupancy reached, and 4 docks share it, so the answer is 4.
Example 2
Input
2
Expected
2
Explanation
Robot 1 goes to dock 1 and robot 2 goes to dock 2. Both docks host exactly 1 robot, the maximum possible occupancy here, and both are tied for it, so the answer is 2.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →