Maximize the number of palindromic Strings | C ++ program for the above approach ; To check if there is any string of odd length ; If there is at least 1 string of odd length . ; If all the strings are of even length . ; Count of 0 's in all  the strings ; Count of 1 's in  all the strings ; If z is even and o is even then ans will be N . ; Otherwise ans will be N - 1. ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int max_palindrome ( string s [ ] , int n ) { int flag = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] . size ( ) % 2 != 0 ) { flag = 1 ; } } if ( flag == 1 ) { return n ; } int z = 0 , o = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < s [ i ] . size ( ) ; j ++ ) { if ( s [ i ] [ j ] == '0' ) z ++ ; else o ++ ; } } if ( o % 2 == 0 && z % 2 == 0 ) { return n ; } else { return n - 1 ; } } int main ( ) { int n = 3 ; string s [ n ] = { "1110" , "100110" , "010101" } ; cout << max_palindrome ( s , n ) ; return 0 ; }