Find one extra character in a string | JavaScript program to find extra character in one string ; store string values in map ; store second string in map with frequency ; store first string in map with frequency ; if the frequency is 1 then this character is which is added extra ; given string ; find Extra Character
function findExtraCharcter ( strA , strB ) { let m1 = new Array ( 256 ) ; for ( let i = 0 ; i < 256 ; i ++ ) m1 [ i ] = 0 ; for ( let i = 0 ; i < strB . length ; i ++ ) m1 [ strB [ i ] . charCodeAt ( 0 ) ] ++ ; for ( let i = 0 ; i < strA . length ; i ++ ) m1 [ strA [ i ] . charCodeAt ( 0 ) ] -- ; for ( let i = 0 ; i < m1 . length ; i ++ ) { if ( m1 [ i ] == 1 ) return String . fromCharCode ( i ) ; } return Number . MIN_VALUE ; } let strA = " " ; let strB = " " ; document . write ( findExtraCharcter ( strA . split ( " " ) , strB . split ( " " ) ) ) ;