title: Print Max and Min Value in Java
body: <p>I have just started practicing on HackerRank to improve my coding skills. I'm mostly using Java as my preferred language. I have got this question, and I have tried my level best to give the solution but didn't clear all the test cases. <strong>I have cleared 5 out 15 test cases</strong>, but still 10 cases are left to be done. Those who are on the hackerrank can see the question by following this link : <a href="https://www.hackerrank.com/challenges/mini-max-sum/problem" rel="nofollow noreferrer">Min-Max Sum</a></p>
  
  <p>I'm anyway giving the brief description of the question : </p>
  
  <p><strong>PROBLEM STATEMENT</strong></p>
  
  <p>Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers.</p>
  
  <p>For example,<code>arr=[1,3,5,7,9]</code>. Our minimum sum is <code>1+3+5+7=16</code> and our maximum sum is <code>3+5+7+9=24</code>. We would print <code>16 24</code></p>
  
  <p><strong>Output Format</strong></p>
  
  <p>Print two space-separated long integers denoting the respective minimum and maximum values that can be calculated by summing exactly four of the five integers. (The output can be greater than a 32 bit integer.)</p>
  
  <p><strong>Sample Input</strong>  <code>1 2 3 4 5</code></p>
  
  <p><strong>Sample Output</strong> <code>10 14</code></p>
  
  <p><strong>Explanation</strong></p>
  
  <p>Our initial numbers are <code>1, 2, 3, 4, and 5</code>. We can calculate the following sums using four of the five integers:</p>
  
  <pre><code>If we sum everything except 1, our sum is 2+3+4+5=14.
  If we sum everything except 2, our sum is 1+3+4+5=13.
  If we sum everything except 3, our sum is 1+2+4+5=12.
  If we sum everything except 4, our sum is 1+2+3+5=11.
  If we sum everything except 5, our sum is 1+2+3+4=10.
  </code></pre>
  
  <p><strong>My Algo</strong></p>
  
  <pre><code>  for(i=0; i&lt;arr.length; i++){
      totSum += arr[i];
    }
  
    sumOne = totSum - arr[0];
    sumTwo = totSum - arr[1];
    sumThree = totSum - arr[2];
    sumFour = totSum - arr[3];
    sumFive = totSum - arr[4];
  
    int[] num = {sumOne, sumTwo, sumThree, sumFour, sumFive};
    int temp = 0;
    for(i=0;i&lt;num.length;i++){
      for(int j=1;j&lt;(num.length-i);j++){
          if(num[j-1] &gt; num[j]){  
              //swap elements  
              temp = num[j-1];  
              num[j-1] = num[j];  
              num[j] = temp;  
          }
      }
    }
  
    System.out.print(num[0] + " " + num[4]);
  </code></pre>
  
  <p>We can also do that by iterating through the <code>num array</code>, and finding the max and min value.</p>
  
  <p>But somehow after all doing this, I don't clear this module. </p>
  
  <p><strong>Please Note :</strong> The number of elements in arr is fixed that is 5 only.</p>
  
  <p>I have got to know that amongst the 10 fails, I got to know about one test case, which is like this : </p>
  
  <p><strong>Input(stdin)</strong>
  <code>256741038 623958417 467905213 714532089 938071625</code></p>
  
  <p><strong>Expected Output</strong>
  <code>2063136757 2744467344</code></p>