summaryrefslogtreecommitdiff
path: root/progs/a423.py
blob: 4bd6530a1e2461c0ee862c3ec5b57910c1b2fc6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
def max_len_sub( 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