← Uber Interview Insights

Uber·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
May 2026

Summary

Took the Uber SWE online assessment and ran into a string problem that was trickier than the usual version I'd seen before.

Questions Asked (1)

Q1

Given a string, find the minimum cost to convert it into a 'wonderful' string (a variant of the classic wonderful string problem where a wonderful string has at most one character appearing an odd number of times).

Algorithms & Data Structures
Author's notes

The base version of this problem is pretty well known but the cost-minimization twist changed the whole approach.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem: define 'wonderful' string and the cost model (e.g., cost to change a character). Then, recognize that the condition depends only on the parity of character counts. Use a bitmask to represent the parity of each character (0 for even, 1 for odd) and compute the minimum cost to reach a mask with at most one set bit.

Pro tip: Discuss the trade-off between time and space: the bitmask DP is O(n * 2^26) which is too large, but you can optimize by only considering masks that appear or using meet-in-the-middle. Also, mention that if the alphabet is small (e.g., lowercase English), the approach is feasible.

1. Clarify the problem

Ask the interviewer to define 'wonderful' string and the cost function. Confirm if cost is per character change and if the alphabet size is fixed (e.g., 26 lowercase letters).

2. Model the parity condition

Represent the parity of each character's count as a bitmask. A wonderful string has a mask with at most one bit set (0 or a power of two).

3. Compute minimum cost to achieve each mask

For each prefix, compute the minimum cost to reach each possible mask. Use dynamic programming where dp[mask] = min cost to achieve that parity mask.

4. Find the answer

The answer is the minimum cost among all masks with at most one bit set. If the cost is to change characters, consider the cost of flipping bits.

5. Optimize and analyze complexity

Discuss optimizations like using a hash map for sparse masks, or meet-in-the-middle if alphabet is large. Analyze time and space complexity.

Key Points to Mention

  • Bitmask representation of parity (0 for even, 1 for odd)
  • Wonderful string condition: mask has at most one set bit
  • Dynamic programming over masks: dp[mask] = min cost
  • Cost model: changing a character flips its parity bit
  • Optimization: only consider reachable masks or use meet-in-the-middle
  • Time complexity: O(n * 2^A) where A is alphabet size, or O(n * number of masks)

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