title: Check Whether Arithmetic Progression Can Formed Given Array
signature: function check_whether_arithmetic_progression_can_formed_given_array(arr, n)
source_py: def check_whether_arithmetic_progression_can_formed_given_array(arr, n):
      if (n == 1):
          return True
      arr.sort()
      d = (arr[1] - arr[0])
      for i in range(2, n):
          if ((arr[i] - arr[(i - 1)]) != d):
              return False
      return True
source_cpp: bool check_whether_arithmetic_progression_can_formed_given_array(vector<int> arr, int n) {
    if ( n == 1 ) return true;
    sort(arr.begin(), arr.end());
    int d = arr [ 1 ] - arr [ 0 ];
    for ( int i = 2;
    i < n;
    i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false;
    return true;
  }
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({1, 4, 16, 64}, 4, false)
      print(string.format("TEST-0...%s",result))
  
      result = driver({0, 4, 8, 12}, 4, true)
      print(string.format("TEST-1...%s",result))
  
      result = driver({-2, 0, 2, 4, 6}, 5, true)
      print(string.format("TEST-2...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 7, true)
      print(string.format("TEST-3...%s",result))
  
      result = driver({46, 56, 66, 76, 86}, 5, true)
      print(string.format("TEST-4...%s",result))
  
      result = driver({46, 56, 56, 66, 76, 86}, 6, false)
      print(string.format("TEST-5...%s",result))
  
      result = driver({7, 9, 11, 21, 44, 45, 61, 67, 78, 97, 98, 99}, 11, false)
      print(string.format("TEST-6...%s",result))
  
      result = driver({-96, -84, -74, -70, -68, -62, -50, -50, -38, -36, -36, -36, -34, -34, -28, -28, -26, -18, -12, -4, -4, -2, -2, 6, 6, 14, 24, 34, 36, 44, 50, 54, 54, 62, 64, 66, 70, 74, 74, 78, 84, 86}, 33, false)
      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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 33, false)
      print(string.format("TEST-8...%s",result))
  
      result = driver({1, 3, 5, 11, 14, 15, 15, 17, 18, 19, 20, 20, 22, 32, 33, 35, 36, 37, 39, 44, 45, 46, 51, 54, 57, 58, 61, 61, 63, 64, 67, 69, 70, 70, 79, 82, 86, 89, 92, 93, 95, 99}, 40, false)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": false, "inputs": {"arr": [1, 4, 16, 64], "n": 4}}, {"idx": 1, "outputs": true, "inputs": {"arr": [0, 4, 8, 12], "n": 4}}, {"idx": 2, "outputs": true, "inputs": {"arr": [-2, 0, 2, 4, 6], "n": 5}}, {"idx": 3, "outputs": true, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "n": 7}}, {"idx": 4, "outputs": true, "inputs": {"arr": [46, 56, 66, 76, 86], "n": 5}}, {"idx": 5, "outputs": false, "inputs": {"arr": [46, 56, 56, 66, 76, 86], "n": 6}}, {"idx": 6, "outputs": false, "inputs": {"arr": [7, 9, 11, 21, 44, 45, 61, 67, 78, 97, 98, 99], "n": 11}}, {"idx": 7, "outputs": false, "inputs": {"arr": [-96, -84, -74, -70, -68, -62, -50, -50, -38, -36, -36, -36, -34, -34, -28, -28, -26, -18, -12, -4, -4, -2, -2, 6, 6, 14, 24, 34, 36, 44, 50, 54, 54, 62, 64, 66, 70, 74, 74, 78, 84, 86], "n": 33}}, {"idx": 8, "outputs": false, "inputs": {"arr": [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], "n": 33}}, {"idx": 9, "outputs": false, "inputs": {"arr": [1, 3, 5, 11, 14, 15, 15, 17, 18, 19, 20, 20, 22, 32, 33, 35, 36, 37, 39, 44, 45, 46, 51, 54, 57, 58, 61, 61, 63, 64, 67, 69, 70, 70, 79, 82, 86, 89, 92, 93, 95, 99], "n": 40}}]
question_info.extension: lua
question_info.entry_fn_name: check_whether_arithmetic_progression_can_formed_given_array
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__