Minimum Number of Manipulations required to make two Strings Anagram Without Deletion of Character | Counts the no of manipulations required ; Store the count of character ; Iterate though the first String and update count ; Iterate through the second string update char_count . If character is not found in char_count then increase count ; Driver code
function countManipulations ( s1 , s2 ) { let count = 0 ; let char_count = new Array ( 26 ) ; for ( let i = 0 ; i < char_count . length ; i ++ ) { char_count [ i ] = 0 ; } for ( let i = 0 ; i < s1 . length ; i ++ ) char_count [ s1 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( let i = 0 ; i < s2 . length ; i ++ ) { char_count [ s2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] -- ; } for ( let i = 0 ; i < 26 ; ++ i ) { if ( char_count [ i ] != 0 ) { count += Math . abs ( char_count [ i ] ) ; } } return count ; } let s1 = " " ; let s2 = " " ; document . write ( countManipulations ( s1 , s2 ) ) ;