Statistics

Problem Statement for "SumUnique"

Problem Statement

You are given a list of int values. We wish to find the sum of these values, however we want to ignore duplicates. Return the sum of the unique values in the list.

Definition

Class:
SumUnique
Method:
getSum
Parameters:
int[]
Returns:
int
Method signature:
int getSum(int[] values)
(be sure your method is public)

Constraints

  • values will contain between 1 and 50 elements, inclusive.
  • Each element of values will be between 1 and 100, inclusive.

Examples

  1. { 1, 2, 3, 4, 5 }

    Returns: 15

    The values are all unique, so we return 1 + 2 + 3 + 4 + 5 = 15.

  2. { 1, 2, 3, 4, 3 }

    Returns: 10

    The value 3 is duplicated, so we only count it once. 1 + 2 + 3 + 4 = 10.

  3. { 1, 1, 1, 1, 1, 1, 1, 1, 1 }

    Returns: 1

  4. { 18, 22, 9, 1, 7, 18, 13, 49, 13, 9, 49, 49, 7 }

    Returns: 119

  5. { 1 }

    Returns: 1

  6. {1, 2, 3, 4, 5 }

    Returns: 15

  7. {1, 2, 3, 4, 3 }

    Returns: 10

  8. {1, 1, 1, 1, 1 }

    Returns: 1

  9. {1, 1, 1, 1, 1, 1, 1, 1, 1 }

    Returns: 1

  10. {1, 3, 3, 4 }

    Returns: 8

  11. {1, 2, 2, 1, 1, 2, 1, 2, 1, 2 }

    Returns: 3

  12. {100, 100, 100, 100 }

    Returns: 100

  13. {18, 22, 9, 1, 7, 18, 13, 49, 13, 9, 49, 49, 7 }

    Returns: 119

  14. {1, 1, 1 }

    Returns: 1

  15. {1 }

    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: