FastPrepCount Palindromic Concatenation Pairs
Problems/Count Palindromic Concatenation Pairs

Count Palindromic Concatenation Pairs

Salesforce logoSalesforceOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given a list of lowercase strings words.

Count the number of index pairs (i, j) such that i < j and some permutation of the concatenation words[i] + words[j] can form a palindrome.

A string can be rearranged into a palindrome if at most one character has an odd frequency.

Function

countPalindromicConcatenationPairs(words: String[]) → long

Examples

Example 1

words = ["ab","ba","abc","c"]return = 3

The valid pairs are (0,1), (0,2), and (1,2).

Example 2

words = ["aa","bb","ab"]return = 1

Only "aa" + "bb" can be rearranged into a palindrome.

Constraints

  • 1 <= words.length
  • Total length of all strings is at most 3 * 10^5.
  • words[i] contains only lowercase English letters.

More Salesforce Online Assessment questions

  • Count Subarrays With Product Equal to KOA · Seen Nov 2026
  • Minimum No-Repeat Segments After One Character RemovalOA · Seen Nov 2026
  • Get Message StatusOA · Seen Nov 2026
  • Minimum Unique-Character Segments After DeletionOA · Seen Sep 2026
  • Run-Length String CompressionOA · Seen Sep 2026
  • Maximum Requests in WindowOA · Seen Sep 2026
  • Final Pod Counts After LogsOA · Seen Aug 2026
  • Minimum Removals to Balance ArrayOA · Seen Aug 2026
  • Is This Date a Weekend?OA · Seen Aug 2026
  • Maximum Barbell WeightOA · Seen Jul 2026

Salesforce interview experiences

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience
  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public long countPalindromicConcatenationPairs(String[] words) {
      // write your code here
    }
}
Checking account…