human
Longest subsequence such that adjacent elements have at least one common digit | Returns Length of maximum Length subsequence.
To store the Length of the maximum Length subsequence.
To store current element arr [ i ].
To store the Length of the sub - sequence ending at index i and having common digit d.
To store digits present in current element.
To store Length of maximum Length subsequence ending at index i.
For first element maximum Length is 1 for each digit.
Find digits of each element , then find Length of subsequence for each digit and then find local maximum.
Find digits in current element.
For each digit present find Length of subsequence and find local maximum.
Update value of dp [ i ] [ d ] for each digit present in current element to local maximum found ..
Update maximum Length with local maximum.
Driver code"
Solution in Python:

Give me a code to longest subsequence such that adjacent elements have at least one common digit and the other steps required?
assistant
#Here is code to longest subsequence such that adjacent elements have at least one common digit and the other steps required.
 def findSubsequence ( arr , n ) :
	Len = 1
	tmp = 0
	i , j , d = 0 , 0 , 0
	dp = [ [ 0 for i in range ( 10 ) ] for i in range ( n ) ]
	cnt = [ 0 for i in range ( 10 ) ]
	locMax = 0
	tmp = arr [ 0 ]
	while ( tmp > 0 ) :
		dp [ 0 ] [ tmp % 10 ] = 1
		tmp //= 10
	for i in range ( 1 , n ) :
		tmp = arr [ i ]
		locMax = 1
		cnt = [ 0 for i in range ( 10 ) ]
		while ( tmp > 0 ) :
			cnt [ tmp % 10 ] = 1
			tmp //= 10
		for d in range ( 10 ) :
			if ( cnt [ d ] ) :
				dp [ i ] [ d ] = 1
				for j in range ( i ) :
					dp [ i ] [ d ] = max ( dp [ i ] [ d ] , dp [ j ] [ d ] + 1 )
					locMax = max ( dp [ i ] [ d ] , locMax )
		for d in range ( 10 ) :
			if ( cnt [ d ] ) :
				dp [ i ] [ d ] = locMax
		Len = max ( Len , locMax )
	return Len
arr = [ 1 , 12 , 44 , 29 , 33 , 96 , 89 ]
n = len ( arr )
print ( findSubsequence ( arr , n ) )