← IBM Interview Insights

IBM·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

IBM coding round for a Software Engineer position, one algorithmic problem that looked manageable until I actually tried to implement it cleanly under pressure.

Questions Asked (1)

Q1

Given an array of strings where you can freely redistribute characters across all strings (only string lengths are fixed), return the maximum number of strings that can be made palindromes at the same time.

Algorithms & Data Structures
Author's notes

My first instinct was to think about each string in isolation, which was completely wrong.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, recognize that a palindrome can have at most one character with an odd count. Since characters can be redistributed, count the total frequency of each character across all strings. Then, determine how many strings can be formed such that each has at most one odd-count character, respecting the fixed lengths of the original strings.

Pro tip: Clarify with the interviewer whether the goal is to maximize the number of palindromic strings or to determine if all strings can be palindromes. Also, consider edge cases like strings of length 1 and empty strings.

1. Understand the problem

Restate the problem to ensure clarity: we can rearrange characters arbitrarily across all strings, but the length of each string remains fixed. We need to maximize the number of strings that are palindromes.

2. Count character frequencies

Compute the total frequency of each character (e.g., using a hash map or array of size 26 for lowercase letters). This global pool is what we can distribute.

3. Determine odd counts

Count how many characters have an odd frequency (let this be odd_count). Each palindrome can absorb at most one odd-count character (as its center).

4. Allocate odd characters to strings

We can assign at most one odd character to each string. So the maximum number of palindromes is limited by the number of strings and the number of odd characters. However, we must also ensure that the total length of the strings can accommodate the characters.

5. Compute maximum palindromes

The answer is the minimum of the number of strings and the number of odd characters, but also consider that if a string has even length, it cannot have an odd-count character as its center. Adjust accordingly: for even-length strings, they require all character counts to be even. So we need to pair up odd characters or assign them to odd-length strings.

Key Points to Mention

  • Palindrome property: at most one character with odd frequency.
  • Global character frequency count across all strings.
  • Fixed string lengths constrain the distribution of characters.
  • Odd-length strings can accommodate one odd-count character; even-length strings cannot.
  • Maximizing palindromes involves pairing odd counts or using them as centers.
  • Edge cases: strings of length 0 or 1, all characters same, etc.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.