<awangdev>1040. Moving Stones Until Consecutive II_1.java
public int[] numMovesStonesII(int[] stones) {
        Arrays.sort(stones);
        
        int n = stones.length, left = 0, right = 0, min = n;
        int max = Math.max(stones[n - 1] - stones[1] - n + 2, stones[n - 2] - stones[0] - n + 2);
        
        while (right < n) {
            while (stones[right] - stones[left] + 1 > n) left++;
            int count = right - left + 1;
            if (count == n - 1 && stones[right] - stones[left] + 1 == n - 1) {
                min = Math.min(min, 2);
            } else {
                min = Math.min(min, n - count);
            }
            right++;
        }
        
        return new int[]{min, max};
    }
public int [ ] sample_funcname ( int [ ] var_0 ) {
  Arrays . sort ( var_0 ) ;
  int var_4 = var_0 . length , var_6 = 0 , var_7 = 0 , min = var_4 ;
  int max = Math . max ( var_0 [ var_4 - 1 ] - var_0 [ 1 ] - var_4 + 2 , var_0 [ var_4 - 2 ] - var_0 [ 0 ] - var_4 + 2 ) ;
  while ( var_7 < var_4 ) {
    while ( var_0 [ var_7 ] - var_0 [ var_6 ] + 1 > var_4 ) var_6 ++ ;
    int var_13 = var_7 - var_6 + 1 ;
    if ( var_13 == var_4 - 1 && var_0 [ var_7 ] - var_0 [ var_6 ] + 1 == var_4 - 1 ) {
      min = Math . min ( min , 2 ) ;
    }
    else {
      min = Math . min ( min , var_4 - var_13 ) ;
    }
    var_7 ++ ;
  }
  return new int [ ] {
    min , max };
  }
  