Statistics

Problem Statement for "CommonDigits"

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

  4. 1

    Returns: 1

  5. 1000000000

    Returns: 0

  6. 1222333

    Returns: 2

  7. 55555555

    Returns: 5

  8. 246426

    Returns: 2

  9. 246810121

    Returns: 1

  10. 34857634

    Returns: 3

  11. 2003

    Returns: 0

  12. 567891234

    Returns: 5

  13. 914347281

    Returns: 1

  14. 774322344

    Returns: 4

  15. 112222211

    Returns: 2

  16. 362838476

    Returns: 3

  17. 174921776

    Returns: 7

  18. 283647976

    Returns: 6

  19. 23475614

    Returns: 4

  20. 554433221

    Returns: 5

  21. 74656624

    Returns: 6

  22. 888999

    Returns: 8

  23. 3344

    Returns: 3

  24. 333999

    Returns: 3

  25. 877788

    Returns: 8

  26. 321

    Returns: 3

  27. 991155

    Returns: 9

  28. 999888

    Returns: 9

  29. 7887

    Returns: 7

  30. 433344

    Returns: 4

  31. 123

    Returns: 1


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: