package com.fishercoder.solutions;

import java.util.Arrays;

/**
 * 908. Smallest Range I
 *
 * Given an array A of integers, for each integer A[i] we may choose any x with -K <= x <= K, and add x to A[i].
 *
 * After this process, we have some array B.
 *
 * Return the smallest possible difference between the maximum value of B and the minimum value of B.
 *
 *
 *
 * Example 1:
 *
 * Input: A = [1], K = 0
 * Output: 0
 * Explanation: B = [1]
 * Example 2:
 *
 * Input: A = [0,10], K = 2
 * Output: 6
 * Explanation: B = [2,8]
 * Example 3:
 *
 * Input: A = [1,3,6], K = 3
 * Output: 0
 * Explanation: B = [3,3,3] or B = [4,4,4]
 *
 *
 * Note:
 *
 * 1 <= A.length <= 10000
 * 0 <= A[i] <= 10000
 * 0 <= K <= 10000
 */
public class _908 {
    public static class Solution1 {
        public int smallestRangeI(int[] A, int K) {
          Arrays.sort(A);
          int smallestPlus = A[0] + K;
          int biggestMinus = A[A.length - 1] - K;
          int diff = biggestMinus - smallestPlus;
          if (diff > 0) {
              return diff;
          } else {
              return 0;
          }
      }
  }

  public static class Solution2 {
      public int smallestRangeI(int[] A, int K) {
          int min = A[0];
          int max = A[0];

          for (int k : A) {
            min = Math.min(min, k);
            max = Math.max(max, k);
          }

          return Math.max(max - min - 2 * K, 0);
      }
  }
}

@@ -59,669 +59,8 @@
 s;%0A%0A
-/**%0A * 908. Smallest Range I%0A *%0A * Given an array A of integers, for each integer A%5Bi%5D we may choose any x with -K %3C= x %3C= K, and add x to A%5Bi%5D.%0A *%0A * After this process, we have some array B.%0A *%0A * Return the smallest possible difference between the maximum value of B and the minimum value of B.%0A *%0A *%0A *%0A * Example 1:%0A *%0A * Input: A = %5B1%5D, K = 0%0A * Output: 0%0A * Explanation: B = %5B1%5D%0A * Example 2:%0A *%0A * Input: A = %5B0,10%5D, K = 2%0A * Output: 6%0A * Explanation: B = %5B2,8%5D%0A * Example 3:%0A *%0A * Input: A = %5B1,3,6%5D, K = 3%0A * Output: 0%0A * Explanation: B = %5B3,3,3%5D or B = %5B4,4,4%5D%0A *%0A *%0A * Note:%0A *%0A * 1 %3C= A.length %3C= 10000%0A * 0 %3C= A%5Bi%5D %3C= 10000%0A * 0 %3C= K %3C= 10000%0A */%0A
 publ
@@ -173,16 +173,18 @@
         
+  
 Arrays.s
@@ -191,16 +191,18 @@
 ort(A);%0A
+  
         
@@ -238,24 +238,26 @@
 ;%0A          
+  
 int biggestM
@@ -280,24 +280,26 @@
 h - 1%5D - K;%0A
+  
           in
@@ -336,16 +336,18 @@
 stPlus;%0A
+  
         
@@ -374,24 +374,26 @@
             
+  
 return diff;
@@ -403,16 +403,18 @@
         
+  
 %7D else %7B
@@ -424,24 +424,26 @@
             
+ 
+ 
 return 0;%0A  
@@ -450,18 +450,22 @@
         
-%7D%0A
+  %7D%0A  
       %7D%0A
@@ -466,19 +466,23 @@
     %7D%0A  
+ 
+ 
 %7D%0A%0A
+  
   public
@@ -507,16 +507,18 @@
 tion2 %7B%0A
+  
       pu
@@ -565,24 +565,26 @@
 %7B%0A          
+  
 int min = A%5B
@@ -587,16 +587,18 @@
 = A%5B0%5D;%0A
+  
         
@@ -616,16 +616,18 @@
  A%5B0%5D;%0A%0A
+  
         
@@ -658,16 +658,20 @@
         
+    
 min = Ma
@@ -698,16 +698,20 @@
         
+ 
+   
 max = Ma
@@ -732,27 +732,31 @@
 ;%0A          
+  
 %7D%0A%0A
+  
           re
@@ -798,16 +798,20 @@
 ;%0A      
-%7D%0A
+  %7D%0A  
   %7D%0A%7D%0A

refactor 908