Statistics

Problem Statement for "BooksNumbering"

Problem Statement

A new library was founded in our city. The books were labeled 1, 2, 3, 4, etc., with no leading zeroes. A total of usedDigits digits were used to create the labels. Return the total number of books in the library, or -1 if usedDigits does not correspond to a valid solution.

Definition

Class:
BooksNumbering
Method:
numberOfBooks
Parameters:
int
Returns:
int
Method signature:
int numberOfBooks(int usedDigits)
(be sure your method is public)

Constraints

  • usedDigits will be between 1 and 2 * 109, inclusive.

Examples

  1. 11

    Returns: 10

    Each of the first 9 numbers (1-9) contain one digit. Number 10 contains 2 digits. Therefore, there's a total of 11 digits.

  2. 10

    Returns: -1

    There is no possible solution. It takes 9 digits to label 9 books, and 11 digits to label 10 books.

  3. 189

    Returns: 99

  4. 192

    Returns: 100

  5. 1999999998

    Returns: 234567900

  6. 2000000000

    Returns: -1

  7. 7

    Returns: 7

  8. 1

    Returns: 1

  9. 1863927342

    Returns: 219448716

  10. 1863927343

    Returns: -1

  11. 9

    Returns: 9

  12. 99

    Returns: 54

  13. 999

    Returns: 369

  14. 9999

    Returns: -1

  15. 99999

    Returns: 22221

  16. 999999

    Returns: 185184

  17. 9999999

    Returns: -1

  18. 99999999

    Returns: -1

  19. 999999999

    Returns: 123456789

  20. 189

    Returns: 99

    99

  21. 2889

    Returns: 999

    999

  22. 38889

    Returns: 9999

    9999

  23. 488889

    Returns: 99999

    99999

  24. 5888889

    Returns: 999999

    999999

  25. 68888889

    Returns: 9999999

    9999999

  26. 788888889

    Returns: 99999999

    99999999

  27. 192

    Returns: 100

    100

  28. 2893

    Returns: 1000

    1000

  29. 38894

    Returns: 10000

    10000

  30. 488895

    Returns: 100000

    100000

  31. 5888896

    Returns: 1000000

    1000000

  32. 68888897

    Returns: 10000000

    10000000

  33. 788888898

    Returns: 100000000

    100000000

  34. 12

    Returns: -1

  35. 10

    Returns: -1

  36. 193

    Returns: -1

  37. 191

    Returns: -1

  38. 2896

    Returns: -1

  39. 2891

    Returns: -1

  40. 38897

    Returns: -1

  41. 38891

    Returns: -1

  42. 488898

    Returns: -1

  43. 488890

    Returns: -1

  44. 5888902

    Returns: -1

  45. 5888890

    Returns: -1

  46. 68888904

    Returns: -1

  47. 68888890

    Returns: -1

  48. 788888900

    Returns: -1

  49. 788888894

    Returns: -1

  50. 756419241

    Returns: 95941293

  51. 756419240

    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: