Minimum removals required such that a string can be rearranged to form a palindrome | Function to find the number of deletions required such that characters of the string can be rearranged to form a palindrome ; Stores frequency of characters ; Store the frequency of each character in frequency array ; let a = parseInt ( str [ i ] - 97 ) ; ; Count number of characters with odd frequency ; If count is 1 or 0 , return 0 ; Otherwise , return count - 1 ; Function call to find minimum number of deletions required
function minDeletions ( str ) { var fre = new Array ( 26 ) ; fre . fill ( 0 ) ; var n = str . length ; for ( var i = 0 ; i < n ; i ++ ) { fre [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] += 1 ; } var count = 0 ; for ( var i = 0 ; i < 26 ; i ++ ) { if ( fre [ i ] % 2 ) { count += 1 ; } } if ( count == 0 count == 1 ) { return 0 ; } else { return count - 1 ; } } var str = " " ; document . write ( minDeletions ( str ) + " " ) ;