title: Maximize Sum Consecutive Differences Circular Array
signature: maximize_sum_consecutive_differences_circular_array <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(8L, 9L, 12L, 13L, 17L, 21L, 24L, 29L, 37L, 37L, 39L, 40L, 41L, 45L, 49L, 50L, 53L, 54L, 56L, 59L, 60L, 60L, 70L, 71L, 72L, 74L, 77L, 77L, 78L, 85L, 89L, 89L, 90L, 90L, 95L, 98L, 98L), 34L, 
          1454L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-92L, -84L, -84L, -84L, -84L, -80L, -80L, -80L, -64L, -52L, -40L, -32L, -20L, -18L, -16L, 0L, 6L, 14L, 20L, 26L, 28L, 30L, 32L, 32L, 44L, 48L, 48L, 52L, 54L, 66L, 76L, 78L, 88L, 92L, 94L, 96L), 24L, 
          1980L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 1L, 1L, 1L), 3L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(7L, 47L, 53L, 59L, 80L, 84L, 96L), 5L, 
          170L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-88L, -80L, -68L, -62L, -60L, -60L, -48L, -46L, -44L, -38L, -16L, -16L, 0L, 0L, 2L, 8L, 20L, 36L, 40L, 40L, 44L, 54L, 60L, 68L, 70L, 82L, 82L, 84L, 92L, 94L, 96L), 29L, 
          2812L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 32L, 
          20L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(2L, 5L, 10L, 11L, 13L, 14L, 15L, 17L, 17L, 23L, 23L, 24L, 27L, 27L, 28L, 29L, 30L, 40L, 42L, 43L, 46L, 47L, 51L, 52L, 57L, 64L, 65L, 73L, 74L, 75L, 76L, 77L, 81L, 81L, 82L, 87L, 89L, 93L, 95L, 95L, 99L), 35L, 
          1542L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-94L, -92L, -84L, -84L, -76L, -72L, -72L, -72L, -54L, -48L, -38L, -22L, -16L, -12L, 2L, 2L, 12L, 20L, 20L, 24L, 26L, 26L, 26L, 26L, 30L, 38L, 48L, 50L, 84L, 86L), 21L, 
          1608L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 37L, 
          20L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(7L, 8L, 27L, 31L, 37L, 46L, 46L, 52L, 53L, 53L, 56L, 57L, 57L, 73L, 73L, 74L, 80L, 84L, 97L), 13L, 
          344L
      )))
  
  }
  
  main()
source_py: def maximize_sum_consecutive_differences_circular_array(arr, n):
      sum = 0
      arr.sort()
      for i in range(0, int((n / 2))):
          sum -= (2 * arr[i])
          sum += (2 * arr[((n - i) - 1)])
      return sum
source_cpp: int maximize_sum_consecutive_differences_circular_array(vector<int> arr, int n) {
    int sum = 0;
    sort(arr.begin(), arr.end());
    for ( int i = 0;
    i < n / 2;
    i ++ ) {
      sum -= ( 2 * arr [ i ] );
      sum += ( 2 * arr [ n - i - 1 ] );
    }
    return sum;
  }