← nebius Interview Insights

nebius·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Interviewed for a software engineer role at Nebius and got a string/palindrome pairing problem that looked deceptively clean on the surface. The bit manipulation angle was the whole key and I'm not sure I would've landed on it cleanly under pressure.

Questions Asked (1)

Q1

Given a list of lowercase strings, count the number of unordered pairs (i, j) where i < j such that the combined characters of the two strings can be rearranged into a palindrome.

Algorithms & Data Structures
Author's notes

The palindrome condition boils down to: at most one character has an odd frequency across both strings combined.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Reduce each string to a bitmask representing the parity of character counts, since a palindrome can have at most one character with odd frequency. Then count pairs of strings whose bitmasks differ in at most one bit (including identical masks). Use a hash map to count frequencies of each mask and compute the total efficiently.

Pro tip: Mention that the bitmask approach works because there are only 26 lowercase letters, so the mask fits in an integer. Also, clarify that pairs with identical masks are valid because their combined character counts are all even.

1. Understand the palindrome condition

Explain that a multiset of characters can form a palindrome if and only if at most one character has an odd count. This is the key insight.

2. Represent each string as a bitmask

For each string, compute a 26-bit integer where the i-th bit is 1 if the count of the i-th letter is odd, else 0. This mask captures the parity of character frequencies.

3. Count pairs with compatible masks

Two strings can form a palindrome together if their masks differ in at most one bit (i.e., XOR has at most one set bit). Use a hash map to count frequencies of each mask.

4. Compute total pairs efficiently

For each mask, add pairs with the same mask (choose 2) and pairs with masks that differ by exactly one bit. Iterate over all masks and their possible single-bit flips.

5. Analyze time and space complexity

Time: O(N * 26) to compute masks and O(N * 26) to count pairs, so O(26N) = O(N). Space: O(N) for the hash map. Mention that 26 is constant.

Key Points to Mention

  • Palindrome condition: at most one character with odd frequency.
  • Bitmask representation: 26 bits for lowercase letters, using XOR to combine parities.
  • Two strings are compatible if their masks are equal or differ by exactly one bit.
  • Use a frequency map of masks to avoid O(N^2) pair checking.
  • Time complexity O(N * 26) and space O(N).
  • Edge cases: empty strings, single-character strings, and large N.

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