← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Did a coding round for a SWE role at Uber. One question, classic-ish number manipulation problem. Not a lot of context to share but it was the kind of thing that feels easy until you're actually writing it out.

Questions Asked (1)

Q1

Given a number, find the closest palindrome to it.

Algorithms & Data Structures
Author's notes

I thought I had this figured out in the first two minutes and then spent the next fifteen realizing I did not.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the definition of 'closest' (absolute difference, tie-breaking) and edge cases like single-digit numbers. Then, generate candidate palindromes by mirroring the first half of the number and adjusting the middle digit, and compare their differences to find the closest.

Pro tip: Always discuss tie-breaking rules and handle edge cases like numbers with all 9s (e.g., 999 -> 1001) and numbers like 10 (closest is 9 or 11). Also, mention that the closest palindrome can be found by considering only a few candidates derived from the first half.

1. Clarify requirements and edge cases

Ask about tie-breaking (e.g., if two palindromes are equally close, which to return?), and consider edge cases like single-digit numbers, numbers with all 9s, and numbers like 10.

2. Generate candidate palindromes

Extract the first half of the number, and generate palindromes by mirroring it. Also consider decrementing and incrementing the first half by 1 to cover cases where the closest palindrome has a different first half.

3. Handle even and odd length numbers

For odd-length numbers, mirror the first half including the middle digit; for even-length, mirror the entire first half. Ensure the generated palindrome has the same number of digits as the original (except when it overflows to the next digit count).

4. Compare and select the closest

Compute the absolute difference between the original number and each candidate palindrome. Select the one with the smallest difference, applying tie-breaking rules if necessary.

5. Analyze complexity and test

Discuss time and space complexity (O(d) where d is the number of digits). Walk through examples to verify correctness, including edge cases.

Key Points to Mention

  • Definition of palindrome and how to construct one by mirroring the first half.
  • Tie-breaking rules: if two palindromes are equally close, which one to return? (e.g., smaller or larger).
  • Edge cases: single-digit numbers, numbers like 10 (closest is 9 or 11), numbers with all 9s (e.g., 999 -> 1001).
  • Generating candidates by considering first half, first half - 1, and first half + 1.
  • Time and space complexity: O(d) time and O(1) space if done carefully.
  • Handling overflow when incrementing the first half (e.g., 999 -> 1001).

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