Statistics

Problem Statement for "SelfCatalogue"

Problem Statement

A self-catalogue is a sentence that truthfully and comprehensively describes its own composition. In this problem, we are concerned with sentences that count numerals occurring in themselves, such as the following.

This sentence contains 1 occurrence of 0, 2 occurrences of 1, 3 occurrences of 2, and 2 occurrences of 3.

The above is a self-catalogue because it gives an accurate count for each numeral occurring in itself. The following sentence, although accurate in the counts that it gives, is not a self-catalogue because it does not give a count for the numeral 3.

This sentence contains 3 occurrences of 1, 1 occurrence of 8, and 1 occurrence of 9.

A self-catalogue must not give more than one count for the same numeral. Thus, the following is not a self-catalogue.

This sentence contains 4 occurrences of 4, and 4 occurrences of 4.

Given a int[] specifying a count for each of the numerals 0 through 9, try to find a self-catalogue that agrees with these counts. A count of 0 means that the numeral does not appear in the sentence at all, and a specified count of -1 means that any count (including 0) is acceptable. If there is no sentence meeting this specification, return an empty int[]. Otherwise, return a int[] of the same size as the input and containing the same non-negative counts, but with each -1 replaced by an accurate count. If several self-catalogues are possible, choose the one that yields the smallest value in element 0 of the result. If a tie remains, select for the smallest value in element 1; if there is still a tie, select for the smallest value in element 2; and so forth.

Definition

Class:
SelfCatalogue
Method:
construct
Parameters:
int[]
Returns:
int[]
Method signature:
int[] construct(int[] counts)
(be sure your method is public)

Notes

  • Leading zeros are not permitted for any number appearing in a self-catalogue.

Constraints

  • counts contains exactly 10 elements.
  • Each element of counts is between -1 and 100, inclusive.

Examples

  1. {1, -1, -1, -1, -1, -1, -1, -1, -1, -1}

    Returns: {1, 2, 3, 2, 0, 0, 0, 0, 0, 0 }

    The first sentence from the problem statement satisfies the input specification that there be exactly one occurrence of the numeral 0: This sentence contains 1 occurrence of 0, 2 occurrences of 1, 3 occurrences of 2, and 2 occurrences of 3.

  2. {100, -1, -1, -1, -1, -1, -1, -1, -1, -1}

    Returns: { }

    It is impossible to make a self-catalogue with 100 zeros.

  3. {1, 7, 3, -1, -1, -1, -1, -1, -1, -1}

    Returns: {1, 7, 3, 2, 1, 1, 1, 2, 1, 1 }

    This sentence contains 1 occurrence of 0, 7 occurrences of 1, 3 occurrences of 2, 2 occurrences of 3, 1 occurrence of 4, 1 occurrence of 5, 1 occurrence of 6, 2 occurrences of 7, 1 occurrence of 8, and 1 occurrence of 9.

  4. {1, 11, -1, -1, -1, -1, -1, -1, -1, -1}

    Returns: {1, 11, 0, 1, 1, 1, 1, 1, 1, 1 }

    Note that 11 contains two occurrences of 1.

  5. {-1, 11, -1, -1, -1, -1, -1, -1, -1, -1}

    Returns: {0, 11, 1, 1, 1, 1, 1, 1, 1, 1 }

  6. {2, -1, -1, -1, -1, -1, -1, -1, -1, -1}

    Returns: { }

  7. {-1, -1, 2, -1, -1, -1, -1, -1, -1, -1}

    Returns: {0, 0, 2, 0, 0, 0, 0, 0, 0, 0 }

  8. {-1, -1, 3, -1, -1, -1, -1, -1, -1, -1}

    Returns: {0, 2, 3, 2, 0, 0, 0, 0, 0, 1 }

  9. {-1, -1, 4, -1, -1, -1, -1, -1, -1, -1}

    Returns: { }

  10. {-1, -1, -1, 3, -1, -1, -1, -1, -1, -1}

    Returns: {0, 3, 0, 3, 0, 0, 0, 0, 1, 1 }

  11. {-1, -1, -1, 4, -1, -1, -1, -1, -1, -1}

    Returns: { }

  12. {-1, -1, -1, -1, 4, -1, -1, -1, -1, -1}

    Returns: { }

  13. {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}

    Returns: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

    The following self-catalogue illustrates this degenerate case: This is a sentence.

  14. {0,-1,-1,-1,-1,-1,-1,-1,-1,-1}

    Returns: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

  15. {1,-1,-1,-1,-1,-1,-1,-1,-1,-1}

    Returns: {1, 2, 3, 2, 0, 0, 0, 0, 0, 0 }

  16. {-1,0,-1,-1,-1,-1,-1,-1,-1,-1}

    Returns: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

  17. {-1,2,-1,-1,-1,-1,-1,-1,-1,-1}

    Returns: {0, 2, 3, 2, 0, 0, 0, 0, 0, 1 }

  18. {-1,3,-1,-1,-1,-1,-1,-1,-1,-1}

    Returns: {0, 3, 0, 3, 0, 0, 0, 0, 1, 1 }

  19. {-1,4,-1,-1,-1,-1,-1,-1,-1,-1}

    Returns: {0, 4, 3, 2, 2, 0, 0, 1, 1, 1 }

  20. {-1,5,-1,-1,-1,-1,-1,-1,-1,-1}

    Returns: {0, 5, 3, 2, 0, 2, 1, 1, 1, 1 }

  21. {-1,6,-1,-1,-1,-1,-1,-1,-1,-1}

    Returns: {0, 6, 3, 2, 1, 1, 2, 1, 1, 1 }

  22. {-1,7,-1,-1,-1,-1,-1,-1,-1,-1}

    Returns: {1, 7, 3, 2, 1, 1, 1, 2, 1, 1 }

  23. {-1,11,-1,-1,-1,-1,-1,-1,-1,-1}

    Returns: {0, 11, 1, 1, 1, 1, 1, 1, 1, 1 }

  24. {-1,-1,0,-1,-1,-1,-1,-1,-1,-1}

    Returns: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

  25. {-1,-1,1,-1,-1,-1,-1,-1,-1,-1}

    Returns: {0, 3, 1, 3, 0, 0, 0, 0, 0, 1 }

  26. {-1,-1,2,-1,-1,-1,-1,-1,-1,-1}

    Returns: {0, 0, 2, 0, 0, 0, 0, 0, 0, 0 }

  27. {-1,-1,3,-1,-1,-1,-1,-1,-1,-1}

    Returns: {0, 2, 3, 2, 0, 0, 0, 0, 0, 1 }

  28. {-1,-1,-1,0,-1,-1,-1,-1,-1,-1}

    Returns: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

  29. {-1,-1,-1,1,-1,-1,-1,-1,-1,-1}

    Returns: {0, 11, 1, 1, 1, 1, 1, 1, 1, 1 }

  30. {-1,-1,-1,2,-1,-1,-1,-1,-1,-1}

    Returns: {0, 2, 3, 2, 0, 0, 0, 0, 0, 1 }

  31. {-1,-1,-1,3,-1,-1,-1,-1,-1,-1}

    Returns: {0, 3, 0, 3, 0, 0, 0, 0, 1, 1 }

  32. {-1,-1,-1,-1,0,-1,-1,-1,-1,-1}

    Returns: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

  33. {-1,-1,-1,-1,1,-1,-1,-1,-1,-1}

    Returns: {0, 2, 3, 2, 1, 0, 0, 0, 0, 0 }

  34. {-1,-1,-1,-1,2,-1,-1,-1,-1,-1}

    Returns: {0, 4, 3, 2, 2, 0, 0, 1, 1, 1 }

  35. {-1,-1,-1,-1,-1,0,-1,-1,-1,-1}

    Returns: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

  36. {-1,-1,-1,-1,-1,1,-1,-1,-1,-1}

    Returns: {0, 2, 3, 2, 0, 1, 0, 0, 0, 0 }

  37. {-1,-1,-1,-1,-1,2,-1,-1,-1,-1}

    Returns: {0, 5, 3, 2, 0, 2, 1, 1, 1, 1 }

  38. {-1,-1,-1,-1,-1,5,-1,-1,-1,-1}

    Returns: { }

  39. {-1,-1,-1,-1,-1,-1,0,-1,-1,-1}

    Returns: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

  40. {-1,-1,-1,-1,-1,-1,1,-1,-1,-1}

    Returns: {0, 2, 3, 2, 0, 0, 1, 0, 0, 0 }

  41. {-1,-1,-1,-1,-1,-1,2,-1,-1,-1}

    Returns: {0, 6, 3, 2, 1, 1, 2, 1, 1, 1 }

  42. {-1,-1,-1,-1,-1,-1,-1,0,-1,-1}

    Returns: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

  43. {-1,-1,-1,-1,-1,-1,-1,1,-1,-1}

    Returns: {0, 2, 3, 2, 0, 0, 0, 1, 0, 0 }

  44. {-1,-1,-1,-1,-1,-1,-1,2,-1,-1}

    Returns: {1, 7, 3, 2, 1, 1, 1, 2, 1, 1 }

  45. {-1,-1,-1,-1,-1,-1,-1,-1,0,-1}

    Returns: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

  46. {-1,-1,-1,-1,-1,-1,-1,-1,1,-1}

    Returns: {0, 2, 3, 2, 0, 0, 0, 0, 1, 0 }

  47. {-1,-1,-1,-1,-1,-1,-1,-1,-1,0}

    Returns: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

  48. {-1,-1,-1,-1,-1,-1,-1,-1,-1,1}

    Returns: {0, 2, 3, 2, 0, 0, 0, 0, 0, 1 }

  49. {0,-1,-1,-1,-1,-1,-1,-1,-1,-1}

    Returns: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

  50. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

    Returns: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

  51. {1, 11, 0, 1, 1, 1, 1, 1, 1, 1}

    Returns: {1, 11, 0, 1, 1, 1, 1, 1, 1, 1 }

  52. {0, -1, -1, 1, -1, -1, -1, -1, -1, -1}

    Returns: {0, 11, 1, 1, 1, 1, 1, 1, 1, 1 }

  53. {-1, -1, -1, -1, -1, -1, -1, 2, -1, -1 }

    Returns: {1, 7, 3, 2, 1, 1, 1, 2, 1, 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: