7 kyu
zero-balanced Array
524 of 1,282aweleshetu
Description:
An array is called zero-balanced if its elements sum to 0
and each element has its corresponding negative (i.e. if there are x
elements n
, then there must be x
negatives -n
). For example,
[1, -1, 2, -2] — zero-balanced, sum of elements is 0 + each element has its own negative;
[0, 1, -1] — zero-balanced, 0 is the negative of itself (0 == -0);
[3] — not zero-balanced; sum != 0;
[3, -2, -1] — not zero-balanced, sum == 0, but the array has 3 but not its negative, -3;
[1, 1, 1, 1, -1, 3, -3, -3] — despite having sum == 0 and all elements having their negatives, the latters must have the same amount as their originals, which doesn't comply here (four '1' and one '-1'), therefore, this array is not zero-balanced.
Write a function that returns true
if its argument is zero-balanced array, else return false
.
Note: an empty array will not sum to 0 since there are no elements in it, therefore, it should be treated as not zero-balanced.
Arrays
Fundamentals
Similar Kata:
Stats:
Created | Sep 24, 2017 |
Published | Sep 24, 2017 |
Warriors Trained | 2277 |
Total Skips | 40 |
Total Code Submissions | 11014 |
Total Times Completed | 1282 |
JavaScript Completions | 524 |
C# Completions | 114 |
Python Completions | 598 |
Ruby Completions | 104 |
Crystal Completions | 10 |
Total Stars | 23 |
% of votes with a positive feedback rating | 84% of 323 |
Total "Very Satisfied" Votes | 244 |
Total "Somewhat Satisfied" Votes | 57 |
Total "Not Satisfied" Votes | 22 |
Total Rank Assessments | 12 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |