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

    You are viewing a single comment's thread. Return to all comments →

  • Kanahaiya
    3 years ago+ 11 comments

    Hello friends,

    In this video tutorial, I have explained hackerrank mini-max sum solution algorithm. hackerrank mini-max sum problem can be solved by using one for loop. The complexity of mini-max sum hackerrank solution is O (n).

    If interested to know more about the generic algorithm in details-

    click here for the video explanation of generic algorithm with complexity analysis.

    or you can click on the image too to follow youtube tutorial.

    Here is the working solution:-

    source code :

    static void miniMaxSum(int[] arr) {
    		long min = 0, max = 0, sum = 0;
    		min = arr[0];
    		max = min;
    		sum = min;
    		for (int i = 1; i < arr.length; i++) {
    			sum += arr[i];
    			if (arr[i] < min) {
    				min = arr[i];
    			}
    			if (arr[i] > max) {
    				max = arr[i];
    			}
    		}
    		System.out.print((sum - max) + " " + (sum - min));
    
    	}
    

    Would really appreciate your feedback like, dislike , comment etc. on my video.

    Do not forget to upvote, if you find it useful.

    149|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature