```python
def max_len_sub( arr, n):
    if n == 0:
        return 0

    # dp[x] will store the length of the subsequence ending with number x
    dp = {}
    max_length = 0

    for num in arr:
        # The length of the subsequence ending in num is 1 (for num itself)
        # plus the length of the subsequence ending in num - 1.
        # If no subsequence ending in num - 1 has been found yet, its length is 0.
        length = dp.get(num - 1, 0) + 1
        
        # Store the length of the subsequence ending in num.
        # This might update a previously stored length for num if a longer
        # preceding sequence is found later in the array.
        dp[num] = length
        
        # Update the overall maximum length found so far.
        if length > max_length:
            max_length = length

    return max_length

```