Check if substrings from three given strings can be concatenated to form a palindrome | Java program for the above approach ; 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
import java . util . * ; class GFG { static String make_palindrome ( String S1 , String S2 , String S3 ) { int maskA = 0 , maskC = 0 ; for ( char i : S1 . toCharArray ( ) ) maskA |= ( 1 << ( i - ' a ' ) ) ; for ( char i : S3 . toCharArray ( ) ) maskC |= ( 1 << ( i - ' a ' ) ) ; if ( ( maskA & maskC ) > 0 ) return " YES " ; return " NO " ; } public static void main ( String [ ] args ) { String S1 = " adcb " , S2 = " bcdb " , S3 = " abe " ; System . out . print ( make_palindrome ( S1 , S2 , S3 ) ) ; } }