问题描述:
Write a function to find the maximum length of the subsequence with difference between adjacent elements for the given array.

测试用例:
['assert max_len_sub([2, 5, 6, 3, 7, 6, 5, 8], 8) == 5', 'assert max_len_sub([-2, -1, 5, -1, 4, 0, 3], 7) == 4', 'assert max_len_sub([9, 11, 13, 15, 18], 5) == 1']

生成的代码:
def max_len_sub(arr, n):
    if n == 0:
        return 0
    
    max_length = 1
    current_length = 1
    
    for i in range(1, n):
        if abs(arr[i] - arr[i - 1]) <= 1:
            current_length += 1
            max_length = max(max_length, current_length)
        else:
            current_length = 1
            
    return max_length

# Test cases
assert max_len_sub([2, 5, 6, 3, 7, 6, 5, 8], 8) == 5
assert max_len_sub([-2, -1, 5, -1, 4, 0, 3], 7) == 4
assert max_len_sub([9, 11, 13, 15, 18], 5) == 1