Trains the technique from
LeetCode 3035Maximum Palindromes After OperationsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A club noticeboard carries a row of word strips. Strip i currently shows the lowercase letter cards spelling words[i], one card per slot, and no slot is ever left empty.
The steward may pick any two slots anywhere on the board, on the same strip or on two different strips, and trade the cards sitting in them. She may do this as often as she likes, in any order. Every strip keeps the number of slots it started with; only which card sits in which slot ever changes.
A strip reads both ways when the cards along it spell the same sequence read left to right as read right to left.
Return the largest number of strips that can be made to read both ways at the same time.
Example 1
The board holds two a cards, two b cards, and one each of c, d, e and f. Moving both a cards onto the two-slot strip and both b cards onto the other two-slot strip leaves them showing `"aa"` and `"bb"`, and the four-slot strip is left holding c, d, e and f, which are four different cards.
Example 2
Trading the b on the first strip for the b on the second gives `"aa"` and `"bb"`, and both strips then read the same in either direction.
Example 3
All five cards on the board are different letters, so any two-slot strip shows two different cards and the three-slot strip shows three.
Example 4
A single slot always reads the same in either direction, so the one strip counts.
Example 5
Trading the b into the middle slot leaves the strip showing `"aba"`.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def max_palindromes_after_operations(words: list[str]) -> int:public int maxPalindromesAfterOperations(String[] words)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.