Maximize Palindromic Words
Updated
Problem statement
You are given words. You may swap any two character positions, including positions in different words, any number of times. Each word keeps its original length.
Return the largest number of words that can be palindromes at the same time after the swaps. A palindrome reads the same in both directions.
For this exercise, assume characters may move freely between any positions. You must keep all characters and every word length. A character left over from a pair may be used as the center of an odd-length palindrome.
Function
maximumPalindromicWords(words: String[]) → intExamples
Example 1
words = ["aa","bc","cc"]return = 2There are two available character pairs: one aa and one cc. Each length-two word needs one pair, so at most two can be palindromes. The arrangement ["aa","cc","bc"] reaches two.
Example 2
words = ["a","bc","def"]return = 1No character occurs twice, so no length-two or length-three word can be a palindrome. The length-one word is always a palindrome.
Example 3
words = ["ab","ba"]return = 2Rearrange the four characters into ["aa","bb"]. Both words are palindromes.
Constraints
1 <= words.length <= 1000.1 <= words[i].length <= 1000.- Every character is a lowercase English letter.
- The sum of all word lengths is at most
10000.
More Squarepoint Capital interview questions
- Evaluating Circuit ExpressionsOA · Seen Jul 2026
- Match an XOR-Adjusted SumOA · Seen Oct 2025
- Minimize the Sum with Ceiling HalvesOA · Seen Oct 2025
- Longest Increasing Subsequence from Two ArraysOA · Seen Oct 2025
- Resolve Overlapping Price RangesOA · Seen Dec 2024
- Empty ShelfOA · Seen Sep 2024
- Suggested ProductsOA · Seen Sep 2024
- Newton Square Root to a Guaranteed TolerancePHONE SCREEN · Seen Nov 2026
- Probability of Consecutive HeadsPHONE SCREEN · Seen Nov 2026
- Three Points in a Semicircle: Monte Carlo EstimatePHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Minimum Distinct Prefix CostChubb · OAChubb interview questions
- Decode Words with Anagram KeysCresta · OACresta interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Longest String ChainVisa · OAVisa interview questions
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Return Exact Cash Register ChangeBank of America · OA
- Largest Binary Number by ConcatenationAdobe · OAAdobe interview questions
- Rearrange Songs by AuthorZomato / Eternal · OAZomato / Eternal interview questions
- Frequently Bought TogetherAmazon · OA
- Viral Content BalancerTikTok · OATikTok interview questions