TopcoderArchiveVisit Topcoder
SRM22 Nov 2008
SRM 426

DistinctDigits

Problem statement, definition, constraints, and public examples.

Problem Statement

Consider the set of numbers formed by taking every number between low and high, inclusive, and sorting the digits of each number in non-increasing order (the numbers are initially written without any extra leading zeros). Return the number of distinct numbers in this new set.

Definition

Class:
DistinctDigits
Method:
count
Parameters:
int, int
Returns:
int
Method signature:
int count(int low, int high)
(be sure your method is public)

Constraints

  • high will be between 1 and 100,000,000 (10^8), inclusive.
  • low will be between 1 and high, inclusive.

Examples

  1. 1
    20
    Returns: 20
    All of the integers between 1 and 20 have distincts sets of digits.
  2. 1
    30
    Returns: 29
    "21" has the same digits as "12" when sorted. All the rest are still distinct.
  3. 151
    309
    Returns: 98
  4. 1
    15000
    Returns: 1641
  5. 153697
    154689
    Returns: 318
  6. 1000
    10000000
    Returns: 19159
Back to all problems