Longest Uncommon Subsequence | function to calculate length of longest uncommon subsequence ; creating an unordered map to map strings to their frequency ; traversing all elements of vector strArr ; Creating all possible subsequences , i . e 2 ^ n ; ( ( i >> j ) & 1 ) determines which character goes into t ; If common subsequence is found , increment its frequency ; traversing the map ; if frequency equals 1 ; input strings
def findLUSlength ( a , b ) : NEW_LINE INDENT map = dict ( ) NEW_LINE strArr = [ ] NEW_LINE strArr . append ( a ) NEW_LINE strArr . append ( b ) NEW_LINE for s in strArr : NEW_LINE INDENT for i in range ( 1 << len ( s ) ) : NEW_LINE INDENT t = " " NEW_LINE for j in range ( len ( s ) ) : NEW_LINE INDENT if ( ( ( i >> j ) & 1 ) != 0 ) : NEW_LINE INDENT t += s [ j ] NEW_LINE DEDENT DEDENT if ( t in map . keys ( ) ) : NEW_LINE INDENT map [ t ] += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT map [ t ] = 1 NEW_LINE DEDENT DEDENT DEDENT res = 0 NEW_LINE for a in map : NEW_LINE INDENT if ( map [ a ] == 1 ) : NEW_LINE INDENT res = max ( res , len ( a ) ) NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT a = " abcdabcd " NEW_LINE b = " abcabc " NEW_LINE print ( findLUSlength ( a , b ) ) NEW_LINE