← Uber Interview Insights

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

IntermediatePending
Jun 2026

Summary

Took an OA for a Software Engineer role at Uber and got tripped up on a string/palindrome problem. Couldn't crack the optimal solution under time pressure and TLE'd on some cases, so now I'm just waiting and hoping it wasn't a dealbreaker.

Questions Asked (1)

Q1

Given a string, compute the total cost of converting every substring into a palindrome. For example, with the string "abc", the substrings "ab", "bc", and "abc" each cost 1, giving a total of 3.

Algorithms & Data Structures
Author's notes

I got a working solution but it was nowhere near O(n) and it showed.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the cost definition: the minimum number of character replacements to make a substring a palindrome. Then, design an efficient algorithm, likely using dynamic programming to compute costs for all substrings in O(n^2) time, and sum them. Discuss trade-offs between brute force and optimized approaches.

Pro tip: Mention that the cost for a substring is the number of mismatched character pairs from the ends inward, which can be computed incrementally using DP. This shows you understand the problem deeply and can optimize beyond naive O(n^3).

1. Clarify the problem

Confirm that cost means the minimum number of character replacements to make the substring a palindrome, and that we need the sum over all substrings.

2. Define cost computation

For a substring s[i..j], the cost is the number of mismatched pairs (s[i+k] != s[j-k]) for k from 0 to (j-i)/2. This can be computed in O(length) per substring.

3. Optimize with dynamic programming

Use DP to compute costs for all substrings efficiently: cost[i][j] = cost[i+1][j-1] + (s[i] != s[j] ? 1 : 0). This reduces time to O(n^2).

4. Sum and return

Iterate over all substrings, sum their costs, and return the total. Discuss potential overflow and use appropriate data types.

5. Analyze complexity and edge cases

State time and space complexity (O(n^2) time, O(n^2) space, can be optimized to O(n) space). Handle empty string, single character, and large inputs.

Key Points to Mention

  • Definition of cost as minimum replacements to make a palindrome.
  • Dynamic programming recurrence: cost[i][j] = cost[i+1][j-1] + (s[i] != s[j]).
  • Time complexity O(n^2) and space complexity O(n^2), with possible space optimization to O(n).
  • Edge cases: empty string, single character, all same characters, and maximum string length.
  • Comparison with brute force O(n^3) approach to highlight efficiency.
  • Potential for further optimization if needed, but O(n^2) is likely optimal for this problem.

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