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"
productOrSum [10, 41, 8, 16, 20, 36, 9, 13, 20] 3 -> Product
sum_or_product(&[10, 41, 8, 16, 20, 36, 9, 13, 20], 3) // => "product"
sum_or_product([10, 41, 8, 16, 20, 36, 9, 13, 20], 3) # => "product"
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:

More By Author:

Check out these other kata created by adrnel

Stats:

CreatedJan 26, 2019
PublishedJan 26, 2019
Warriors Trained4135
Total Skips34
Total Code Submissions9046
Total Times Completed2913
JavaScript Completions1967
Haskell Completions76
Rust Completions135
Python Completions802
Julia Completions3
Total Stars26
% of votes with a positive feedback rating93% of 509
Total "Very Satisfied" Votes450
Total "Somewhat Satisfied" Votes51
Total "Not Satisfied" Votes8
Total Rank Assessments26
Average Assessed Rank
6 kyu
Highest Assessed Rank
1 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • adrnel Avatar
  • imjasonmiller Avatar
  • JohanWiltink Avatar
  • hobovsky Avatar
  • stellartux Avatar
  • ejini战神 Avatar
  • farhanaditya Avatar
Ad