← IBM Interview Insights

IBM·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

IBM software engineer interview with a string manipulation problem that looks straightforward until you actually think about what's being optimized. The key insight isn't obvious at first glance and I spent a bit too long going down the wrong path.

Questions Asked (1)

Q1

Given an array of strings where you can freely redistribute any character across all strings (string lengths stay fixed), return the maximum number of strings that can simultaneously be made into palindromes.

Algorithms & Data Structures
Author's notes

I got tripped up initially because I was thinking about it per-string instead of globally.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Count the total frequency of each character across all strings and the number of odd-length strings. A palindrome can absorb at most one odd-count character, so the maximum number of palindromes is the number of odd-length strings plus the number of pairs of odd-count characters that can be combined. Specifically, compute the number of odd-count characters (odd_chars) and the number of odd-length strings (odd_len_strings); the answer is odd_len_strings + (odd_chars - odd_len_strings) // 2, provided odd_chars >= odd_len_strings, otherwise it's odd_chars.

Pro tip: Clarify that the redistribution is global and that string lengths are fixed, so the problem reduces to a counting argument. Mention that if odd_chars < odd_len_strings, the answer is odd_chars because each odd-length string needs at least one odd-count character.

1. Understand the problem

Restate the problem: we can redistribute characters arbitrarily across all strings, but each string's length remains fixed. We need to maximize the number of strings that can be made palindromes simultaneously.

2. Identify key constraints

For a string to be a palindrome, at most one character can have an odd count. The total number of odd-count characters across all strings must be distributed among the strings.

3. Count frequencies and odd-length strings

Compute the total frequency of each character across all strings. Also count how many strings have an odd length (odd_len_strings).

4. Compute odd-count characters

Count how many characters have an odd total frequency (odd_chars). This is the total number of odd-count characters available to be placed as the middle character of palindromes.

5. Derive the formula

If odd_chars >= odd_len_strings, the answer is odd_len_strings + (odd_chars - odd_len_strings) // 2. Otherwise, the answer is odd_chars. Explain why: each odd-length string must take one odd-count character as its middle; remaining odd-count characters can be paired to form additional palindromes of even length.

Key Points to Mention

  • Palindrome property: at most one character with odd frequency per string.
  • Global character redistribution means we only care about total character counts, not original string contents.
  • String lengths are fixed, so the number of odd-length strings is predetermined.
  • The number of odd-count characters (odd_chars) and odd-length strings (odd_len_strings) are the only variables needed.
  • Formula: if odd_chars >= odd_len_strings, answer = odd_len_strings + (odd_chars - odd_len_strings) // 2; else answer = odd_chars.
  • Edge cases: when odd_chars < odd_len_strings, some odd-length strings cannot be made palindromes; when odd_chars is large, extra odd-count characters can be paired to form even-length palindromes.

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