Sort by

recency

|

6031 Discussions

|

  • + 0 comments

    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(" ") ) }

     this is simple clean approach in  what it does lets consider sceanario in array we have all value there will be one small value and one greater value if we add all number and minus the greater value we will get smaller number if we minus the smaller value we will get greater Value 
    

    let result = [sum - greaterValue , sum-smallerValue]; console.log( result.join(" ") ) }

  • + 0 comments

    The solution in javascript is:

     let aux = arr.map(item => +item).sort()
        let min = [...aux].slice(0,-1)
        let max = [...aux].slice(1)
        
        console.log(min.reduce((acc, i) => acc+i,0)+ ' ' + max.reduce((acc, i) => acc+i,0))
    
  • + 0 comments

    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

  • + 0 comments

    here is problem with 2nd testcase. you must fix this issue.

  • + 0 comments

    Here is problem solution in Python Java c++ c and javascript - https://programmingoneonone.com/hackerrank-mini-max-sum-problem-solution.html