Company: Visa. experienced 2+_15march
Difficulty: medium
Maximum Palindromes After Swaps A string is a palindrome when it reads the same forwards and backwards, for example mom , a or radar . You are given an array arr of n strings made of lowercase English letters. You may repeat the following operation as many times as you like, including zero times: choose four integers x , y , i , j with 1 <= x, y <= n , 1 <= i <= length(arr[x]) and 1 <= j <= length(arr[y]) , and exchange the letters arr[x][i] and arr[y][j] (1-based indexing). The two chosen letters may sit in different strings or in the same string ( x and y are allowed to be equal). No letter is ever created, destroyed or moved to a different string length — every operation just exchanges two letters of the array. Report the largest number of strings that can be palindromes at the same time after some sequence of operations. Input Format The first line contains the integer n , the number of strings. Each of the next n lines contains one string arr[i] . Output Format P