Skip to content

Instantly share code, notes, and snippets.

@damdafayton
Created April 15, 2022 07:25
Show Gist options
  • Save damdafayton/0a4d9db6dde4908535f66a9b0c141365 to your computer and use it in GitHub Desktop.
Save damdafayton/0a4d9db6dde4908535f66a9b0c141365 to your computer and use it in GitHub Desktop.
/*
Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers.
https://www.hackerrank.com/challenges/mini-max-sum/problem?isFullScreen=true
*/
function miniMaxSum(arr) {
// Write your code here
let min=arr[0], max=arr[0];
arr.forEach((num,i)=>{
min = Math.min(arr[i],min)
// console.log(min,arr[i] )
max = Math.max(arr[i],max)
})
let all = arr.reduce((sum,prev)=>sum+prev)
console.log(all-max, all-min)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment