← Expedia Interview Insights

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

IntermediatePrefer not to say
May 2026

Summary

Expedia coding round, one algorithmic problem that looked manageable until I actually had to implement it efficiently. The substring palindrome anagram counting problem sounds straightforward but the naive approach is way too slow and they clearly wanted the bitmask trick.

Questions Asked (1)

Q1

Given a list of strings, for each string count how many substrings can be rearranged to form a palindrome.

Algorithms & Data Structures
Author's notes

My first instinct was brute force: enumerate all substrings, count character frequencies, check if at most one character has an odd count.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem: for each string, count substrings whose characters can be rearranged into a palindrome. A substring can form a palindrome if at most one character has an odd frequency. Use a bitmask to represent parity of character counts and count pairs of equal masks (or masks differing by one bit) for each string.

Pro tip: Mention that the bitmask approach works because the alphabet is small (e.g., 26 lowercase letters), and precomputing prefix masks allows O(n) per string. Also, discuss handling uppercase or other characters if the problem allows.

1. Clarify the problem

Confirm the definition: substrings that can be rearranged into a palindrome. Ask about character set (e.g., lowercase English letters) and input size to determine optimal approach.

2. Identify the palindrome condition

A string can be rearranged into a palindrome if at most one character has an odd count. For a substring, this means the parity mask (bitmask of odd counts) has at most one bit set.

3. Use prefix parity masks

Compute prefix parity masks for each position. The parity of a substring from i to j is the XOR of prefix masks at i-1 and j. Count pairs of prefix masks that are equal or differ by exactly one bit.

4. Count valid substrings efficiently

For each string, iterate through prefix masks, maintaining a frequency map of masks seen so far. For each current mask, add frequencies of the same mask and masks with one bit flipped (for each character).

5. Analyze complexity and edge cases

Time complexity: O(n * alphabet size) per string, which is O(26n) for lowercase. Space: O(2^alphabet) for the frequency map, but only O(n) distinct masks. Handle empty strings and single-character substrings.

Key Points to Mention

  • Palindrome rearrangement condition: at most one character with odd frequency.
  • Bitmask representation of character parity (e.g., 26-bit integer).
  • Prefix XOR to compute substring parity in O(1).
  • Counting pairs of masks that are equal or differ by one bit.
  • Time complexity: O(n * alphabet size) per string, space O(n) for frequency map.
  • Edge cases: empty string, single character, all same characters.

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