7 kyu

Unique Sum

1,786 of 3,973Alpri Else

Description:

Given a list of integers values, your job is to return the sum of the values; however, if the same integer value appears multiple times in the list, you can only count it once in your sum.

For example:

[ 1, 2, 3] ==> 6

[ 1, 3, 8, 1, 8] ==> 12

[ -1, -1, 5, 2, -7] ==> -1

[] ==> None
[ 1, 2, 3] ==> 6

[ 1, 3, 8, 1, 8] ==> 12

[ -1, -1, 5, 2, -7] ==> -1

[] ==> None
[ 1, 2, 3] ==> 6

[ 1, 3, 8, 1, 8] ==> 12

[ -1, -1, 5, 2, -7] ==> -1

[] ==> None
[ 1, 2, 3] ==> 6

[ 1, 3, 8, 1, 8] ==> 12

[ -1, -1, 5, 2, -7] ==> -1

[] ==> null
Kata.UniqueSum(new List<int> {1, 2, 3}) => 6

Kata.UniqueSum(new List<int> {1, 3, 8, 1, 8}) => 12

Kata.UniqueSum(new List<int> {-1, -1, 5, 2, -7}) => -1

Kata.UniqueSum(new List<int>()) => null

Good Luck!

Lists
Logic
Filtering
Fundamentals

More By Author:

Check out these other kata created by Alpri Else

Stats:

CreatedFeb 3, 2016
PublishedFeb 3, 2016
Warriors Trained4829
Total Skips88
Total Code Submissions14592
Total Times Completed3973
Python Completions1786
Haskell Completions198
Ruby Completions325
JavaScript Completions1427
C# Completions369
Total Stars41
% of votes with a positive feedback rating92% of 806
Total "Very Satisfied" Votes694
Total "Somewhat Satisfied" Votes89
Total "Not Satisfied" Votes23
Total Rank Assessments125
Average Assessed Rank
7 kyu
Highest Assessed Rank
1 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • Alpri Else Avatar
  • CrazyMerlyn Avatar
  • hilary Avatar
  • dougbacelar Avatar
  • aryan-firouzian Avatar
  • Chrono79 Avatar
  • Voile Avatar
  • Souzooka Avatar
  • hobovsky Avatar
  • user8436785 Avatar
Ad