• + 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.