TopcoderArchive
Archive
Algorithm problem

DecreasingNumbers

Problem statement, definition, constraints, and public examples.

Problem Statement

Let us call a non-negative integer a decreasing number if the digits in its decimal representation are in descending order from left to right. For example, 321 and 950 are decreasing numbers, but 322 and 958 are not. List d is the list of all decreasing numbers, sorted in ascending order. Return the n-th element of d (n is 0-indexed), or -1 if no such element exists.

Definition

Class:
DecreasingNumbers
Method:
getNth
Parameters:
int
Returns:
long
Method signature:
long getNth(int n)
(be sure your method is public)

Constraints

  • n will be between 0 and 1000000, inclusive.

Examples

  1. 0
    Returns: 0
    The list d begins with zero.
  2. 18
    Returns: 42
    The eighteenth number is 42.
  3. 500000
    Returns: -1
Back to all problems