Find uncommon characters of the two strings | size of the hash table ; function to find the uncommon characters of the two strings ; mark presence of each character as 0 in the hash table ' present [ ] ' ; for each character of str1 , mark its presence as 1 in ' present [ ] ' ; for each character of str2 ; if a character of str2 is also present in str1 , then mark its presence as - 1 ; else mark its presence as 2 ; print all the uncommon characters ; Driver program to test above
var MAX_CHAR = 26 ; function findAndPrintUncommonChars ( str1 , str2 ) { var present = Array ( MAX_CHAR ) ; for ( var i = 0 ; i < MAX_CHAR ; i ++ ) present [ i ] = 0 ; var l1 = str1 . length ; var l2 = str2 . length ; for ( var i = 0 ; i < l1 ; i ++ ) present [ str1 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] = 1 ; for ( var i = 0 ; i < l2 ; i ++ ) { if ( present [ str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] == 1 || present [ str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] == - 1 ) present [ str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] = - 1 ; else present [ str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] = 2 ; } for ( var i = 0 ; i < MAX_CHAR ; i ++ ) if ( present [ i ] == 1 present [ i ] == 2 ) document . write ( ( String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ) + " " ) ; } var str1 = " " ; var str2 = " " ; findAndPrintUncommonChars ( str1 , str2 ) ;