We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Warmup
- Mini-Max Sum
- Discussions
Mini-Max Sum
Mini-Max Sum
Sort by
recency
|
6031 Discussions
|
Please Login in order to post a comment
function miniMaxSum(arr: number[]): void { let greaterValue = arr[0];
function miniMaxSum(arr: number[]): void { let greaterValue = arr[0]; let smallerValue = arr[0]; let sum = 0
for( let index =0 ; index < arr.length ; index ++ ){ const value = arr[index]; greaterValue = greaterValue > value ? greaterValue : value; smallerValue = smallerValue < value ? smallerValue : value; sum += value; }
let result = [sum - greaterValue , sum-smallerValue]; console.log( result.join(" ") ) }
let result = [sum - greaterValue , sum-smallerValue]; console.log( result.join(" ") ) }
The solution in javascript is:
store the greatest number and the smallest number in two seperate variables get the sum of all the elements of the array...once subtract the max element to get the minimum element sum, once the min element to get the maximum element sum and this way u'll have the solution
here is problem with 2nd testcase. you must fix this issue.
Here is problem solution in Python Java c++ c and javascript - https://programmingoneonone.com/hackerrank-mini-max-sum-problem-solution.html