title: Check Whether Arithmetic Progression Can Formed Given Array
signature: class Solution {
  
      public bool CheckWhetherArithmeticProgressionCanFormedGivenArray(List<int> arr, int n) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(bool actual, bool expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(List<int> arr, int n, bool expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                bool pred_result = solution_cls.PLACEHOLDER_FN_NAME(arr, n); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  new List<int>{1, 4, 16, 64}, 4, 
                  false
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 4, 8, 12}, 4, 
                  true
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-2, 0, 2, 4, 6}, 5, 
                  true
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 7, 
                  true
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{46, 56, 66, 76, 86}, 5, 
                  true
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{46, 56, 56, 66, 76, 86}, 6, 
                  false
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{7, 9, 11, 21, 44, 45, 61, 67, 78, 97, 98, 99}, 11, 
                  false
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-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
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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;
  }