title: Maximum Length Subsequence Difference Adjacent Elements Either 0 1
signature: maximumLengthSubsequenceDifferenceAdjacentElementsEither01 :: [Integer] -> Integer -> Integer
  maximumLengthSubsequenceDifferenceAdjacentElementsEither01 arr n = 
source_py: def maximum_length_subsequence_difference_adjacent_elements_either_0_1(arr, n):
      mls = []
      max = 0
      for i in range(n):
          mls.append(1)
      for i in range(n):
          for j in range(i):
              if ((abs((arr[i] - arr[j])) <= 1) and (mls[i] < (mls[j] + 1))):
                  mls[i] = (mls[j] + 1)
      for i in range(n):
          if (max < mls[i]):
              max = mls[i]
      return max
source_cpp: int maximum_length_subsequence_difference_adjacent_elements_either_0_1(vector<int> arr, int n) {
    int mls [ n ], max = 0;
    for ( int i = 0;
    i < n;
    i ++ ) mls [ i ] = 1;
    for ( int i = 1;
    i < n;
    i ++ ) for ( int j = 0;
    j < i;
    j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) <= 1 && mls [ i ] < mls [ j ] + 1 ) mls [ i ] = mls [ j ] + 1;
    for ( int i = 0;
    i < n;
    i ++ ) if ( max < mls [ i ] ) max = mls [ i ];
    return max;
  }