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. Prepare
  2. Algorithms
  3. Warmup
  4. Mini-Max Sum
  5. Discussions

Mini-Max Sum

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 5192 Discussions, By:

recency

Please Login in order to post a comment

  • allanmontero
    14 hours ago+ 0 comments

    Java solution:

    public static void miniMaxSum(List<Integer> arr) {
            long min = 0; 
            long max = 0;
            Collections.sort(arr);
            for(int i=0;i<arr.size()-1;i++){
                min+=arr.get(i);
            }
            for(int i=1;i<arr.size();i++){
                max+=arr.get(i);
            }
    
            System.out.println(min+" "+max);
        }
    
    0|
    Permalink
  • maheshvar_jp
    18 hours ago+ 0 comments
    def miniMaxSum(arr):
        arr.sort()
        min_val,max_val=0,0
        n=len(arr)
        j=n-1
        for i in range(j):
            min_val+=arr[i]
            i=i+1
            max_val+=arr[j]
            j=j-1
        print(min_val,max_val)![
    
    0|
    Permalink
  • vikasmohite7620
    21 hours ago+ 0 comments

    C++ Solution

    #include<iostream>
    using namespace std;
    
    int main(){
        
        long arr[4];
        for(int i = 0; i < 5; i++){
            cin>>arr[i];
        }
        // Insertion sort
        for(int i = 1; i < 5; i++){
          int temp = arr[i];
          int j = i-1;
          while(j >= 0 && arr[j] > temp){
              arr[j+1] = arr[j];
              j--;
          }
          arr[j+1] = temp;
      }
        // sum without smallest number
        long Without_smallest = 0; // 
        for(int i = 1; i < 5; i++){
            Without_smallest = Without_smallest + arr[i];
        }
        
        //sum without biggest number
        long Without_biggest = 0;
        for(int i = 0; i < 4; i++){
            Without_biggest = Without_biggest + arr[i];
        }
        cout<<Without_biggest<<" "<<Without_smallest;
        return 0;
    }
    
    0|
    Permalink
  • urossevkusic
    2 days ago+ 0 comments

    C++ solution

    void miniMaxSum(vector<int> arr) {
        std::sort(arr.begin(), arr.end());
        std::cout <<
    		std::accumulate(arr.begin(), arr.begin() + 4, (long)0)
    		<< " ";
        std::cout
    		<< std::accumulate(arr.end() - 4, arr.end(), (long)0)
    		<< std::endl;
    }
    
    0|
    Permalink
  • alban_tyrex
    2 days ago+ 0 comments

    Here is my c++ solution, explanation here : https://youtu.be/zcWbM-aaopc

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        vector<int> arr(5);
        for(int i = 0; i < 5; i++) {
            cin >> arr[i];
        }
        auto min_max = minmax_element(arr.begin(), arr.end());
        long long su = 0;
        su = accumulate(arr.begin(), arr.end(), su);
        cout << su - *min_max.second  << " " << su - *min_max.first;
        return 0;
    }
    
    0|
    Permalink
Load more conversations

Need Help?


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