Statistics

Problem Statement for "SmallestOppositeNumber"

Problem Statement

Given is a non-negative integer X.

Construct and return the smallest non-negative integer Y such that (in base 10) each digit that does not appear in X does appear in Y.

Note that Y is not allowed to start with unnecessary leading zeros. (See Examples 2 and 3.)

Definition

Class:
SmallestOppositeNumber
Method:
construct
Parameters:
int
Returns:
int
Method signature:
int construct(int X)
(be sure your method is public)

Notes

  • The constraints guarantee that X has at most 9 digits. Thus, at least one of the digits 0-9 will be missing from X.

Constraints

  • X will be between 0 and 999,999,999, inclusive.

Examples

  1. 2024868

    Returns: 13579

    The digits 0, 2, 4, 6 and 8 appear in the given number X. (Some of them appear more than once, but that does not matter.) The digits that do not appear in the given number X are the digits 1, 3, 5, 7 and 9. All these digits must therefore appear in Y. The smallest non-negative integer that contains these five digits is clearly Y = 13,579.

  2. 0

    Returns: 123456789

    The number X = 0 contains the digit 0. The number Y must contain the digits 1-9. The smallest such Y is obviously 123,456,789.

  3. 123456798

    Returns: 0

    This is almost an inverse of the previous example: X contains all digits other than 0, so Y should contain the digit 0. The smallest non-negative integer that contains the digit 0 is the number 0.

  4. 45678

    Returns: 10239

    Remember that the number Y cannot start with an unnecessary leading zero. Thus, "01239" is not a valid answer. The smallest number that really contains the digits 0, 1, 2, 3, 9 is 10,239.

  5. 1

    Returns: 203456789

  6. 2

    Returns: 103456789

  7. 3

    Returns: 102456789

  8. 4

    Returns: 102356789

  9. 5

    Returns: 102346789

  10. 6

    Returns: 102345789

  11. 7

    Returns: 102345689

  12. 8

    Returns: 102345679

  13. 9

    Returns: 102345678

  14. 10

    Returns: 23456789

  15. 11

    Returns: 203456789

  16. 12

    Returns: 30456789

  17. 333333333

    Returns: 102456789

  18. 123456789

    Returns: 0

  19. 234567890

    Returns: 1

  20. 134567890

    Returns: 2

  21. 124567890

    Returns: 3

  22. 123567890

    Returns: 4

  23. 123467890

    Returns: 5

  24. 123457890

    Returns: 6

  25. 123456890

    Returns: 7

  26. 123456790

    Returns: 8

  27. 123456780

    Returns: 9

  28. 900000000

    Returns: 12345678

  29. 123456781

    Returns: 90

  30. 222444666

    Returns: 1035789

  31. 222000777

    Returns: 1345689

  32. 913285476

    Returns: 0

  33. 913280476

    Returns: 5

  34. 913282476

    Returns: 50

  35. 1456789

    Returns: 203

  36. 2345

    Returns: 106789


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: