← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
Jun 2026Remote

Summary

Uber SWE interview that went deep on string manipulation and palindrome logic. Three questions total, each building on the last, and the follow-ups got pretty gnarly toward the end.

Questions Asked (3)

Q1

Given a non-negative integer as a string with no leading zeros, return the smallest palindromic integer strictly greater than it, also as a string. Aim for O(n) time and O(1) extra space. Handle edge cases like all 9s, single-digit inputs, and cases where the result has more digits than the input (e.g. '99' -> '101').

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I thought I had this one clean but the all-9s case tripped me up for a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem constraints and edge cases, then propose a two-pointer approach that mirrors the left half onto the right half and adjusts the middle if needed to ensure the palindrome is strictly greater. Emphasize O(n) time and O(1) space by modifying the string in place and handling carry propagation carefully.

Pro tip: Mention that you can avoid extra space by reusing the input string and that you should test edge cases like '9', '99', '12321', and '12921' to ensure correctness.

1. Clarify requirements and edge cases

Confirm that the input is a non-negative integer string without leading zeros, and discuss edge cases such as all 9s, single-digit numbers, and cases where the result has more digits.

2. Outline the mirroring approach

Explain that you will create a palindrome by mirroring the left half onto the right half, then compare it with the original to decide if an adjustment is needed.

3. Handle the strictly greater condition

If the mirrored palindrome is not greater, increment the middle digit(s) and propagate any carry, then re-mirror to maintain the palindrome property.

4. Manage carry and digit growth

If the carry propagates beyond the most significant digit (e.g., all 9s), handle the case by creating a number with an additional digit, such as '1' + zeros + '1'.

5. Analyze complexity and test

Confirm O(n) time and O(1) extra space, then walk through examples to validate the solution.

Key Points to Mention

  • Two-pointer technique to compare and mirror halves
  • In-place modification of the string to achieve O(1) extra space
  • Carry propagation when incrementing the middle digit(s)
  • Special case for all 9s: result is '1' followed by zeros and '1'
  • Single-digit inputs: simply increment the digit (e.g., '5' -> '6')
  • Time complexity O(n) due to single pass for mirroring and possible carry propagation

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

Q2

Modify your solution to return the palindrome closest in absolute difference to the input rather than strictly greater. If two palindromes are equidistant, return the smaller one. Explain which candidate palindromes you generate and how you compare their magnitudes without using big-integer libraries.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where I started to feel the pressure.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Generate the same set of candidate palindromes as in the 'next palindrome' problem (mirror of prefix, and mirror of prefix ±1), then compute the absolute difference between each candidate and the input. Compare differences without big integers by comparing lengths and lexicographic order, and return the candidate with the smallest difference, breaking ties by choosing the smaller palindrome.

Pro tip: Mention that you can avoid big integers by comparing the absolute differences as strings: if lengths differ, the longer difference is larger; if lengths are equal, lexicographic comparison works. This shows you understand the underlying numeric representation.

1. Generate candidate palindromes

Create candidates by mirroring the first half of the input: (a) mirror of the prefix, (b) mirror of prefix+1, (c) mirror of prefix-1. Also consider edge cases like all 9s (e.g., 999 -> 1001) and single-digit numbers.

2. Compute absolute differences

For each candidate, compute the absolute difference from the input as a string (or as a numeric value if within safe integer range). Since the input can be very large, represent differences as strings to avoid overflow.

3. Compare differences without big integers

Compare two differences by first comparing their lengths (longer string means larger number). If lengths are equal, compare lexicographically. This avoids converting to big integers.

4. Select the closest palindrome

Iterate through candidates, keeping track of the one with the smallest difference. If a tie occurs (equal differences), choose the smaller palindrome (compare palindromes as strings by length then lexicographically).

5. Handle edge cases and return

Ensure candidates are valid palindromes (e.g., no leading zeros). Return the selected palindrome as a string.

Key Points to Mention

  • Candidate generation: mirror the prefix, and mirror prefix±1 to cover all closest palindromes.
  • Absolute difference comparison: compare string lengths first, then lexicographically if lengths are equal.
  • Tie-breaking: when differences are equal, choose the smaller palindrome (compare by length then lexicographically).
  • Edge cases: single-digit numbers, numbers like 1000 (closest palindrome 999 or 1001), and all 9s.
  • Avoiding big integers: treat numbers as strings and implement custom comparison.
  • Time and space complexity: O(n) time and O(n) space where n is the number of digits.

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

Q3

Now suppose the input is a decimal string with a fixed number of fractional digits, like '123.450'. Define a palindromic decimal as one where the decimal point mirrors itself and digits mirror symmetrically across it. Return the smallest such palindromic decimal strictly greater than the input, preserving the fixed fractional length. Describe how you propagate carries across the decimal point and maintain the fractional digit count.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Yeah this one kind of broke my brain.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Treat the decimal string as two halves split by the decimal point, mirror the left half onto the right to form a palindrome, then if the result is not greater than the input, increment the left half and re-mirror. Handle carries that propagate across the decimal point by incrementing the integer part and resetting fractional digits as needed, ensuring the fractional length remains fixed.

Pro tip: Clarify edge cases upfront, such as all 9s (e.g., '99.99' → '100.001'? Actually with fixed fractional length, it's '100.01' if fractional length is 2) and inputs with leading zeros, to show thoroughness and avoid incorrect assumptions.

1. Parse and Split

Separate the input into integer and fractional parts, noting the fixed number of fractional digits. Identify the left half (including the decimal point if odd length) that will be mirrored.

2. Mirror to Form Palindrome

Create a candidate palindrome by copying the left half in reverse onto the right side, ensuring the decimal point stays in place and fractional digit count is preserved.

3. Compare and Adjust

If the candidate is greater than the input, return it. Otherwise, increment the left half (as a number) by 1, handling carries that may propagate across the decimal point, then re-mirror.

4. Handle Carry Propagation

When incrementing causes a carry beyond the most significant digit (e.g., all 9s), add a new digit and adjust the fractional part to maintain the fixed length, ensuring the decimal point remains correctly positioned.

5. Validate and Return

Verify the result is a valid palindromic decimal with the correct fractional length and strictly greater than the input, then return it as a string.

Key Points to Mention

  • Definition of palindromic decimal: digits mirror symmetrically across the decimal point, and the decimal point itself is the center.
  • Fixed fractional length must be preserved; padding with zeros may be necessary when carries change the integer part length.
  • Carry propagation across the decimal point: incrementing the integer part may require resetting fractional digits to zeros to maintain palindrome property.
  • Edge cases: all 9s (e.g., '99.99' with 2 fractional digits becomes '100.01'), inputs with leading zeros, and very large numbers.
  • Time and space complexity: O(n) time and O(n) space where n is the length of the string, as we may need to scan and construct the result.
  • Trade-offs: string manipulation vs. numeric conversion; string approach avoids overflow and preserves formatting.

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