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 string t ; If common subsequence is found , increment its frequency ; traversing the map ; if frequency equals 1 ; input strings
function findLUSlength ( a , b ) { let map = new Map ( ) ; let strArr = [ ] ; strArr . push ( a ) ; strArr . push ( b ) ; for ( let s = 0 ; s < strArr . length ; s ++ ) { for ( let i = 0 ; i < ( 1 << strArr [ s ] . length ) ; i ++ ) { let t = " " ; for ( let j = 0 ; j < strArr [ s ] . length ; j ++ ) { if ( ( ( i >> j ) & 1 ) != 0 ) t += strArr [ s ] [ j ] ; } if ( map . has ( t ) ) map . set ( t , map . get ( t ) + 1 ) ; else map . set ( t , 1 ) ; } } let res = 0 ; for ( let [ key , value ] of map . entries ( ) ) { if ( value == 1 ) res = Math . max ( res , key . length ) ; } return res ; } let a = " " , b = " " ; document . write ( findLUSlength ( a , b ) ) ;