Check if substrings from three given strings can be concatenated to form a palindrome | Function to check if subStrings from three given Strings can be concatenated to form a palindrome ; Mask for S1 and S2 ; Set ( i - ' a ' ) th bit in maskA ; Set ( i - ' a ' ) th bit in maskC ; If the bitwise AND is > 0 ; Driver Code
function make_palindrome ( S1 , S2 , S3 ) { let maskA = 0 , maskC = 0 ; for ( let i = 0 ; i < S1 . length ; i ++ ) maskA |= ( 1 << ( S1 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) ; for ( let i = 0 ; i < S3 . length ; i ++ ) maskC |= ( 1 << ( S3 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) ; if ( ( maskA & maskC ) > 0 ) return " " ; return " " ; } let S1 = " " , S2 = " " , S3 = " " ; document . write ( make_palindrome ( S1 , S2 , S3 ) ) ;