7 kyu
Larger Product or Sum
1,967 of 2,913adrnel
Description:
Description
For this Kata you will be given an array of numbers and another number n
.
You have to find the sum of the n
largest numbers of the array and the product of the n
smallest numbers of the array, and compare the two.
If the sum of the n
largest numbers is higher, return "sum"
If the product of the n
smallest numbers is higher, return "product"
If the 2 values are equal, return "same"
Note The array will never be empty and n
will always be smaller than the length of the array.
Example
sumOrProduct([10, 41, 8, 16, 20, 36, 9, 13, 20], 3) // => "product"
Explanation
The sum of the 3 highest numbers is 41 + 36 + 20 = 97
The product of the lowest 3 numbers is 8 x 9 x 10 = 720
The product of the 3 lowest numbers is higher than the sum of the 3 highest numbers so the function returns "product"
Fundamentals
Mathematics
Algorithms
Similar Kata:
Stats:
Created | Jan 26, 2019 |
Published | Jan 26, 2019 |
Warriors Trained | 4135 |
Total Skips | 34 |
Total Code Submissions | 9046 |
Total Times Completed | 2913 |
JavaScript Completions | 1967 |
Haskell Completions | 76 |
Rust Completions | 135 |
Python Completions | 802 |
Julia Completions | 3 |
Total Stars | 26 |
% of votes with a positive feedback rating | 93% of 509 |
Total "Very Satisfied" Votes | 450 |
Total "Somewhat Satisfied" Votes | 51 |
Total "Not Satisfied" Votes | 8 |
Total Rank Assessments | 26 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 1 kyu |
Lowest Assessed Rank | 8 kyu |