Maximum Palindromes After Operations
You are given a 0-indexed string array words having length n and containing 0-indexed strings.
You are allowed to perform the following operation any number of times (including zero):
- Choose integers
i,j,x, andysuch that0 <= i, j < n,0 <= x < words[i].length,0 <= y < words[j].length, and swap the characterswords[i][x]andwords[j][y].
Return an integer denoting the maximum number of palindromes words can contain, after performing some operations.
Note: i and j may be equal during an operation.
Example 1
Input
words = ["abbb","ba","aa"]Output
3By swapping
words[0][0] and words[1][0], words becomes ["bbbb", "aa", "aa"], so all three strings are palindromes.Example 2
Input
words = ["abc","ab"]Output
2After swaps,
words can become ["aca", "bb"], so both strings are palindromes.Constraints
- 1 <= words.length <= 1000
- 1 <= words[i].length <= 100
- words[i] consists only of lowercase English letters.