Katkat

Maximize palindromic strings after character swaps

IBMSoftware Engineer · Technical Screen

Last updated

This question evaluates proficiency in string manipulation, combinatorial character-count reasoning, and redistribution of characters under constrained swap operations within the Coding & Algorithms domain.

You are given an integer n and an array of n lowercase strings arr.

Operation (can be performed any number of times): choose two different strings arr[i] and arr[j], pick one character from each string, and swap those two characters.

After performing any sequence of such swaps, return the maximum possible number of strings in arr that are palindromes.

Notes:

  • You may swap characters between any pair of strings, and you may repeat operations indefinitely.
  • Each string’s length must remain the same.

Example:

  • Input: arr = ["pass", "sas", "asps", "df"]
  • Output: 3 (it is possible to make 3 of the strings palindromes).