Statistics

Problem Statement for "SumFullSet"

Problem Statement

Let S be a sequence of (not necessarily distinct) integers. We say that S is closed under addition if it has the following property: For any pair of valid and distinct indices i and j, the number S[i]+S[j] does also occur in the sequence S (one or more times).

Note that the numbers S[i] and S[j] may be equal, only the indices i and j are required to be distinct. Also note that from the definition it follows that any 0-element or 1-element sequence is closed under addition, as there are no valid pairs of distinct indices into such a sequence.

You are given a sequence of integers in a int[] elements. Return "closed" (quotes for clarity) if the given sequence is closed under addition. Otherwise, return "not closed".

Definition

Class:
SumFullSet
Method:
isSumFullSet
Parameters:
int[]
Returns:
String
Method signature:
String isSumFullSet(int[] elements)
(be sure your method is public)

Constraints

  • Number of elements in elements will be between 1 and 50, both inclusive.
  • Each element of elements will be between -50 and 50, both inclusive.

Examples

  1. {-1,0,1}

    Returns: "closed"

    (-1) + 0 = (-1), which does appear in our sequence (-1) + 1 = 0, which does appear in our sequence 0 + 1 = 1, which does appear in our sequence hence, our sequence is closed under addition

  2. {-1,1}

    Returns: "not closed"

  3. {0,1}

    Returns: "closed"

  4. {0,1,1}

    Returns: "not closed"

    This sequence is not closed under addition because 1+1 = 2, which is not an element of our sequence.

  5. {16,0,43,43,-36,-49,-46,-16,40,34,-43,-24,13,-48,45,19,12,0,43,6,26,-23,50,28,-3,21,46,45,-32,-41,0,-27,42,19,47,-36,-21,-1,5,-21,-28,-43,23,-26,-5,21,-41,16,-37,38}

    Returns: "not closed"

  6. {10}

    Returns: "closed"

    A 1-element sequence is closed under addition by definition.

  7. {0}

    Returns: "closed"

  8. {50}

    Returns: "closed"

  9. {0,0}

    Returns: "closed"

  10. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

    Returns: "closed"

  11. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

    Returns: "closed"

  12. {0,35}

    Returns: "closed"

  13. {0,50,0,0}

    Returns: "closed"

  14. {0,-50,0,0,0,0,0,0}

    Returns: "closed"

  15. {0,0,0,49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

    Returns: "closed"

  16. {-50,0,50}

    Returns: "closed"

  17. {-49,49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

    Returns: "closed"

  18. {-49,49,49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

    Returns: "not closed"

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

    Returns: "not closed"

  20. {-3,3}

    Returns: "not closed"

  21. {0,1,2}

    Returns: "not closed"

  22. {0,0,5,5}

    Returns: "not closed"

  23. {-1, 0, 1, -1 }

    Returns: "not closed"

  24. {0, 1, 1, 0 }

    Returns: "not closed"

  25. {-1, 2, 1 }

    Returns: "not closed"

  26. {0, 1, 0 }

    Returns: "closed"

  27. {0, 0, 0, 0 }

    Returns: "closed"

  28. {-50, -50 }

    Returns: "not closed"

  29. {1, 1 }

    Returns: "not closed"

  30. {0, -1, 1 }

    Returns: "closed"

  31. {3, 1, 2 }

    Returns: "not closed"

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

    Returns: "not closed"

  33. {-1, 0, 1, 2 }

    Returns: "not closed"

  34. {0, 2 }

    Returns: "closed"

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

    Returns: "closed"

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

    Returns: "not closed"

  37. {-5, -5, -5, -5, -5 }

    Returns: "not closed"

  38. {0, 1, 0, 1 }

    Returns: "not closed"

  39. {0, 1, -1 }

    Returns: "closed"

  40. {-50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39, -38 }

    Returns: "not closed"

  41. {0, 1, 1 }

    Returns: "not closed"

  42. {1, 2, 3 }

    Returns: "not closed"

  43. {45 }

    Returns: "closed"


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: