Palindromic strings of length 3 possible by using characters of a given string | Function to print all palindromic strings of length 3 that can be formed using characters of string S ; Stores the count of character ; Traverse the string S ; Stores all palindromic strings ; Iterate over the charchaters over the range [ ' a ' , ' z ' ] ; If Hash [ ch ] is equal to 2 ; Iterate over the characters over the range [ ' a ' , ' z ' ] ; Stores all the palindromic string ; Push the s into the set st ; If Hash [ i ] is greater than or equal to 3 ; Iterate over charchaters over the range [ ' a ' , ' z ' ] ; Stores all the palindromic string ; If Hash [ j ] is positive ; Push s into the set st ; Iterate over the set ; Driver Code
function generatePalindrome ( S ) { let Hash = new Map ( ) ; for ( let ch = 0 ; ch < S . length ; ch ++ ) { if ( ! Hash . has ( S [ ch ] ) ) Hash . set ( S [ ch ] , 1 ) ; else { Hash . set ( S [ ch ] , Hash . get ( S [ ch ] ) + 1 ) } } let st = new Set ( ) ; for ( let i = ' ' . charCodeAt ( 0 ) ; i <= ' ' . charCodeAt ( 0 ) ; i ++ ) { if ( Hash . get ( String . fromCharCode ( i ) ) == 2 ) { for ( let j = ' ' . charCodeAt ( 0 ) ; j <= ' ' . charCodeAt ( 0 ) ; j ++ ) { let s = " " ; if ( Hash . get ( String . fromCharCode ( j ) ) && i != j ) { s += String . fromCharCode ( i ) ; s += String . fromCharCode ( j ) ; s += String . fromCharCode ( i ) ; st . add ( s ) ; } } } if ( Hash . get ( String . fromCharCode ( i ) ) >= 3 ) { for ( let j = ' ' . charCodeAt ( 0 ) ; j <= ' ' . charCodeAt ( 0 ) ; j ++ ) { let s = " " ; if ( Hash . get ( String . fromCharCode ( j ) ) ) { s += String . fromCharCode ( i ) ; s += String . fromCharCode ( j ) ; s += String . fromCharCode ( i ) ; st . add ( s ) ; } } } } for ( let item of st . values ( ) ) { document . write ( item + " " ) } } let S = " " ; generatePalindrome ( S ) ;