TopcoderArchiveVisit Topcoder
SRM6 Jan 2003
SRM 128

CommonDigits

Problem statement, definition, constraints, and public examples.

Problem Statement

Create a class CommonDigits with a method digit that takes an int num and returns the single digit that occurs most often in the decimal representation of num (without leading zeros). If several digits occur the same number of times, give preference to the one whose leftmost (most significant) occurrence is farthest to the left.

Definition

Class:
CommonDigits
Method:
digit
Parameters:
int
Returns:
int
Method signature:
int digit(int num)
(be sure your method is public)

Constraints

  • num is between 1 and 1000000000, inclusive.

Examples

  1. 123
    Returns: 1
    All digits occur the same number of times so return the leftmost.
  2. 102030
    Returns: 0
  3. 79888799
    Returns: 9
Back to all problems