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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Mini-Max Sum
  2. Discussions

Mini-Max Sum

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 311 Discussions, By:

votes

Please Login in order to post a comment

  • nkstatedev
    11 months ago+ 9 comments
    1. If you use built in Python sort(), big O time complexity is already (n log n). If you then find sum(), it's (n) complexity. So it gives (n log n + n) and after simplifying (n log n).
    2. If you use sum(), max(), min() is's (n+n+n) = (3n) and after simplifying (n).
    3. Here is an example of one loop solution with time complexity (n) (but it does really matter only for an astronomical length of an input)
    def miniMaxSum(arr):
        min_ = arr[0]
        max_ = arr[0]
        sum_ = 0
        for i in arr:
            sum_ += i
            if i > max_:
                max_ = i
            if i < min_:
                min_ = i
        print(sum_ - max_, sum_ - min_)
    
    31|
    Permalink
    View more Comments..
  • refianmuhammad
    10 months ago+ 6 comments

    JavaScript is kinda cheating

    function miniMaxSum(arr) {
            arr.sort((a, b) => a - b);
    
            let min = arr.slice(0, arr.length - 1).reduce((a,b) => a+b)
            let max = arr.slice(1).reduce((a,b) => a+b)
    
            console.log(min, max)
    }
    
    13|
    Permalink
    View more Comments..
  • darshan1ga17ec01
    11 months ago+ 4 comments
    def miniMaxSum(arr):
        # Write your code here
        print(sum(arr)-max(arr),end=" ")
        print(sum(arr)-min(arr))
    
    11|
    Permalink
    View more Comments..
  • dev_cesarmillan
    10 months ago+ 1 comment

    JAVA CODE public static void miniMaxSum(List arr) { long sumMax = 0; long max = Integer.MIN_VALUE; long min = Integer.MAX_VALUE; long sumMin = 0;

    for(Integer i: arr) {
        if(i <= min){
            min = i;
        } 
        if (i >= max){
            max = i;
        }
    }
    for(Integer j: arr){
        if(min != j){
            sumMax += j;
        }
        if(max != j){
            sumMin += j;
        }
        if(min == max){
            sumMax = sumMin = (min * (arr.size()-1));
        }
    }
    System.out.println(sumMin + " " + sumMax);
    
    }
    
    5|
    Permalink
  • _iamShubham
    11 months ago+ 4 comments

    Python Code

    def miniMaxSum(arr):
        arr.sort()
        print(sum(arr[:4]), sum(arr[1:]))
    
        
    arr=list(map(int ,input().rstrip().split()))    
    miniMaxSum(arr)
    
    3|
    Permalink
    View more Comments..
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature