title: Maximize Sum Consecutive Differences Circular Array
signature: function maximize_sum_consecutive_differences_circular_array(arr, n)
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;
  }
question_info.entry_fn_name: maximize_sum_consecutive_differences_circular_array
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(arr, n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(arr, n) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({8, 9, 12, 13, 17, 21, 24, 29, 37, 37, 39, 40, 41, 45, 49, 50, 53, 54, 56, 59, 60, 60, 70, 71, 72, 74, 77, 77, 78, 85, 89, 89, 90, 90, 95, 98, 98}, 34, 1454)
      print(string.format("TEST-0...%s",result))
  
      result = driver({-92, -84, -84, -84, -84, -80, -80, -80, -64, -52, -40, -32, -20, -18, -16, 0, 6, 14, 20, 26, 28, 30, 32, 32, 44, 48, 48, 52, 54, 66, 76, 78, 88, 92, 94, 96}, 24, 1980)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 0, 1, 1, 1}, 3, 0)
      print(string.format("TEST-2...%s",result))
  
      result = driver({7, 47, 53, 59, 80, 84, 96}, 5, 170)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-88, -80, -68, -62, -60, -60, -48, -46, -44, -38, -16, -16, 0, 0, 2, 8, 20, 36, 40, 40, 44, 54, 60, 68, 70, 82, 82, 84, 92, 94, 96}, 29, 2812)
      print(string.format("TEST-4...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 32, 20)
      print(string.format("TEST-5...%s",result))
  
      result = driver({2, 5, 10, 11, 13, 14, 15, 17, 17, 23, 23, 24, 27, 27, 28, 29, 30, 40, 42, 43, 46, 47, 51, 52, 57, 64, 65, 73, 74, 75, 76, 77, 81, 81, 82, 87, 89, 93, 95, 95, 99}, 35, 1542)
      print(string.format("TEST-6...%s",result))
  
      result = driver({-94, -92, -84, -84, -76, -72, -72, -72, -54, -48, -38, -22, -16, -12, 2, 2, 12, 20, 20, 24, 26, 26, 26, 26, 30, 38, 48, 50, 84, 86}, 21, 1608)
      print(string.format("TEST-7...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 37, 20)
      print(string.format("TEST-8...%s",result))
  
      result = driver({7, 8, 27, 31, 37, 46, 46, 52, 53, 53, 56, 57, 57, 73, 73, 74, 80, 84, 97}, 13, 344)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 1454, "inputs": {"arr": [8, 9, 12, 13, 17, 21, 24, 29, 37, 37, 39, 40, 41, 45, 49, 50, 53, 54, 56, 59, 60, 60, 70, 71, 72, 74, 77, 77, 78, 85, 89, 89, 90, 90, 95, 98, 98], "n": 34}}, {"idx": 1, "outputs": 1980, "inputs": {"arr": [-92, -84, -84, -84, -84, -80, -80, -80, -64, -52, -40, -32, -20, -18, -16, 0, 6, 14, 20, 26, 28, 30, 32, 32, 44, 48, 48, 52, 54, 66, 76, 78, 88, 92, 94, 96], "n": 24}}, {"idx": 2, "outputs": 0, "inputs": {"arr": [0, 0, 0, 1, 1, 1], "n": 3}}, {"idx": 3, "outputs": 170, "inputs": {"arr": [7, 47, 53, 59, 80, 84, 96], "n": 5}}, {"idx": 4, "outputs": 2812, "inputs": {"arr": [-88, -80, -68, -62, -60, -60, -48, -46, -44, -38, -16, -16, 0, 0, 2, 8, 20, 36, 40, 40, 44, 54, 60, 68, 70, 82, 82, 84, 92, 94, 96], "n": 29}}, {"idx": 5, "outputs": 20, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 32}}, {"idx": 6, "outputs": 1542, "inputs": {"arr": [2, 5, 10, 11, 13, 14, 15, 17, 17, 23, 23, 24, 27, 27, 28, 29, 30, 40, 42, 43, 46, 47, 51, 52, 57, 64, 65, 73, 74, 75, 76, 77, 81, 81, 82, 87, 89, 93, 95, 95, 99], "n": 35}}, {"idx": 7, "outputs": 1608, "inputs": {"arr": [-94, -92, -84, -84, -76, -72, -72, -72, -54, -48, -38, -22, -16, -12, 2, 2, 12, 20, 20, 24, 26, 26, 26, 26, 30, 38, 48, 50, 84, 86], "n": 21}}, {"idx": 8, "outputs": 20, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 37}}, {"idx": 9, "outputs": 344, "inputs": {"arr": [7, 8, 27, 31, 37, 46, 46, 52, 53, 53, 56, 57, 57, 73, 73, 74, 80, 84, 97], "n": 13}}]