← 返回 salesforce 的题目列表Maximum Number of Palindromic Strings After Cross-String Character Swaps
类型:online_judge
Problem: Maximum Number of Palindromic Strings (Cross-String Swaps Allowed)
You are given an array arr of n strings consisting only of lowercase English letters.
In one operation, you may choose two distinct strings arr[x] and arr[y], pick an index i in arr[x] and an index j in arr[y], and swap the characters arr[x][i] and arr[y][j].
You may perform any number of operations.
You may only swap characters between different strings (no swaps within the same string).
Return the maximum number of strings that can be made palindromes after performing any number of operations.
Input
arr: an array of strings
Output
An integer: the maximum number of strings that can be rearranged into palindromes via allowed swaps.
Constraints
1 <= n <= 1000
1 <= len(arr[i]) <= 1000
arr[i] contains only 'a' to 'z'
Example 1
Input:
["pass", "sas", "asps", "df"]
Output:
3
Example 2
Input:
["xy", "tz", "abab"]
Output:
2
Example
Input
4
pass
sas
asps
df
Output
3