Statistics

Problem Statement for "DecreasingNumbers"

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

  4. 2

    Returns: 2

  5. 3

    Returns: 3

  6. 4

    Returns: 4

  7. 5

    Returns: 5

  8. 6

    Returns: 6

  9. 7

    Returns: 7

  10. 8

    Returns: 8

  11. 9

    Returns: 9

  12. 10

    Returns: 10

  13. 30

    Returns: 65

  14. 100

    Returns: 750

  15. 200

    Returns: 6510

  16. 239

    Returns: 7643

  17. 300

    Returns: 8765

  18. 400

    Returns: 65410

  19. 500

    Returns: 87631

  20. 534

    Returns: 96431

  21. 566

    Returns: 97610

  22. 600

    Returns: 98543

  23. 700

    Returns: 875432

  24. 749

    Returns: 975320

  25. 800

    Returns: 986431

  26. 900

    Returns: 9764321

  27. 1000

    Returns: 98764320

  28. 1001

    Returns: 98764321

  29. 1002

    Returns: 98765210

  30. 1003

    Returns: 98765310

  31. 1023

    Returns: -1

  32. 1022

    Returns: 9876543210

  33. 487893

    Returns: -1

  34. 1000000

    Returns: -1

  35. 872379

    Returns: -1

  36. 349801

    Returns: -1

  37. 348790

    Returns: -1

  38. 328789

    Returns: -1

  39. 147892

    Returns: -1

  40. 738953

    Returns: -1

  41. 999999

    Returns: -1

  42. 111111

    Returns: -1

  43. 222222

    Returns: -1

  44. 239239

    Returns: -1

  45. 1

    Returns: 1

  46. 1016

    Returns: 987643210

  47. 1050

    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: