title: Length Of The Longest Arithmatic Progression In A Sorted Array
signature: def length_of_the_longest_arithmatic_progression_in_a_sorted_array(set_arg0, n):
source_py: def length_of_the_longest_arithmatic_progression_in_a_sorted_array(set, n):
      if (n <= 2):
          return n
      L = [[0 for x in range(n)] for y in range(n)]
      llap = 2
      for i in range(n):
          L[i][(n - 1)] = 2
      for j in range((n - 2), 0, (- 1)):
          i = (j - 1)
          k = (j + 1)
          while ((i >= 0) and (k <= (n - 1))):
              if ((set[i] + set[k]) < (2 * set[j])):
                  k += 1
              elif ((set[i] + set[k]) > (2 * set[j])):
                  L[i][j] = 2
                  i -= 1
              else:
                  L[i][j] = (L[j][k] + 1)
                  llap = max(llap, L[i][j])
                  i -= 1
                  k += 1
                  while (i >= 0):
                      L[i][j] = 2
                      i -= 1
      return llap
source_cpp: int length_of_the_longest_arithmatic_progression_in_a_sorted_array(vector<int> set, int n) {
    if ( n <= 2 ) return n;
    int L [ n ] [ n ];
    int llap = 2;
    for ( int i = 0;
    i < n;
    i ++ ) L [ i ] [ n - 1 ] = 2;
    for ( int j = n - 2;
    j >= 1;
    j -- ) {
      int i = j - 1, k = j + 1;
      while ( i >= 0 && k <= n - 1 ) {
        if ( set [ i ] + set [ k ] < 2 * set [ j ] ) k ++;
        else if ( set [ i ] + set [ k ] > 2 * set [ j ] ) {
          L [ i ] [ j ] = 2, i --;
        }
        else {
          L [ i ] [ j ] = L [ j ] [ k ] + 1;
          llap = max ( llap, L [ i ] [ j ] );
          i --;
          k ++;
        }
      }
      while ( i >= 0 ) {
        L [ i ] [ j ] = 2;
        i --;
      }
    }
    return llap;
  }
question_info.test_code: import array
  import bisect
  import collections
  import datetime
  import functools
  import heapq
  import itertools
  import math
  import queue
  import re
  import string
  import sys
  from typing import Any, Dict, List, Optional, Set
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  def validate_solution(actual, expected):
      return actual == expected
  
  def driver(set_arg0, n, expected):
      try:
          if validate_solution(PLACEHOLDER_FN_NAME(
              set_arg0, n),
              expected
          ):
              return "PASSED"
          return "FAILED"
      except Exception as exception_obj:
          return type(exception_obj).__name__
      
  if __name__ == "__main__":
      result = driver([3, 4, 4, 7, 8, 19, 21, 22, 25, 27, 28, 29, 38, 40, 41, 42, 43, 46, 50, 50, 53, 53, 54, 55, 60, 64, 64, 69, 70, 75, 77, 81, 81, 82, 86, 87, 87, 88, 91, 94, 97], 27, 4)
      print(f"TEST-0...{result}")
  
      result = driver([40, -6, 50, -18, 42, 78, 38, -90, -44, -42, -86, 78, -68, 2, -32, -20, -44, 54, 80, 54, 70, 26, 82, -14, -74, -20, 74, 82], 21, 2)
      print(f"TEST-1...{result}")
  
      result = driver([0, 0, 0, 0, 1, 1, 1], 5, 4)
      print(f"TEST-2...{result}")
  
      result = driver([76, 80], 1, 1)
      print(f"TEST-3...{result}")
  
      result = driver([-92, -90, -88, -76, -76, -60, -46, -40, -24, -8, -8, -6, 2, 12, 36, 38, 58, 76, 80], 13, 3)
      print(f"TEST-4...{result}")
  
      result = driver([1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1], 15, 4)
      print(f"TEST-5...{result}")
  
      result = driver([5, 8, 11, 27, 27, 32, 32, 37, 50, 51, 55, 61, 62, 68, 73, 83], 8, 3)
      print(f"TEST-6...{result}")
  
      result = driver([52, -74, -32, -64, -52, -60, -70, 36, 70, 40, 40, -18, 90, -70, -82, -64, -8, -6, 36, 4, -58, 62, -96, 78, 36, 90, -70, -6, -84, 24, 84, 32, -90, 36, 70, -60, -56, 78, 48, 34, -16, 80, 82, 58, 14, -6, -8, 76], 29, 2)
      print(f"TEST-7...{result}")
  
      result = driver([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], 27, 15)
      print(f"TEST-8...{result}")
  
      result = driver([11, 21, 76, 45, 8, 49, 97, 66, 17, 11, 87, 4, 34, 89, 79, 88, 6, 91, 19, 56, 91, 25, 17, 90, 26, 59, 34, 32, 43, 17, 98, 39, 72, 78, 93, 43], 26, 2)
      print(f"TEST-9...{result}")
  
      sys.exit(0)
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.entry_fn_name: length_of_the_longest_arithmatic_progression_in_a_sorted_array
question_info.test_list: [{"idx": 0, "outputs": 4, "inputs": {"set_arg0": [3, 4, 4, 7, 8, 19, 21, 22, 25, 27, 28, 29, 38, 40, 41, 42, 43, 46, 50, 50, 53, 53, 54, 55, 60, 64, 64, 69, 70, 75, 77, 81, 81, 82, 86, 87, 87, 88, 91, 94, 97], "n": 27}}, {"idx": 1, "outputs": 2, "inputs": {"set_arg0": [40, -6, 50, -18, 42, 78, 38, -90, -44, -42, -86, 78, -68, 2, -32, -20, -44, 54, 80, 54, 70, 26, 82, -14, -74, -20, 74, 82], "n": 21}}, {"idx": 2, "outputs": 4, "inputs": {"set_arg0": [0, 0, 0, 0, 1, 1, 1], "n": 5}}, {"idx": 3, "outputs": 1, "inputs": {"set_arg0": [76, 80], "n": 1}}, {"idx": 4, "outputs": 3, "inputs": {"set_arg0": [-92, -90, -88, -76, -76, -60, -46, -40, -24, -8, -8, -6, 2, 12, 36, 38, 58, 76, 80], "n": 13}}, {"idx": 5, "outputs": 4, "inputs": {"set_arg0": [1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1], "n": 15}}, {"idx": 6, "outputs": 3, "inputs": {"set_arg0": [5, 8, 11, 27, 27, 32, 32, 37, 50, 51, 55, 61, 62, 68, 73, 83], "n": 8}}, {"idx": 7, "outputs": 2, "inputs": {"set_arg0": [52, -74, -32, -64, -52, -60, -70, 36, 70, 40, 40, -18, 90, -70, -82, -64, -8, -6, 36, 4, -58, 62, -96, 78, 36, 90, -70, -6, -84, 24, 84, 32, -90, 36, 70, -60, -56, 78, 48, 34, -16, 80, 82, 58, 14, -6, -8, 76], "n": 29}}, {"idx": 8, "outputs": 15, "inputs": {"set_arg0": [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], "n": 27}}, {"idx": 9, "outputs": 2, "inputs": {"set_arg0": [11, 21, 76, 45, 8, 49, 97, 66, 17, 11, 87, 4, 34, 89, 79, 88, 6, 91, 19, 56, 91, 25, 17, 90, 26, 59, 34, 32, 43, 17, 98, 39, 72, 78, 93, 43], "n": 26}}]
question_info.entry_cls_name: Solution