← Uber Interview Insights

Uber·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Uber ML engineer screen, one coding problem that looks easy until you realize the naive approach won't cut it on time complexity. Pretty standard vibe but the follow-up on optimization is where it gets real.

Questions Asked (1)

Q1

Given a sorted array of integers, return a new array of the squares of each element, also sorted in non-decreasing order. Can you do it in O(n) time?

Algorithms & Data Structures
Author's notes

My first instinct was just square everything and sort, which is O(n log n) and they immediately asked if I could do better.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints (e.g., input size, sorted order, duplicates) and then propose the two-pointer technique from both ends to achieve O(n) time. Explain that since the array is sorted, the largest squares come from either the leftmost (most negative) or rightmost (most positive) elements, so you can fill the result array from the end. Walk through a small example to demonstrate correctness and edge cases.

Pro tip: Mention that this approach avoids the O(n log n) sort and uses O(n) extra space, which is optimal for the output. Also, relate it to how ML engineers often need to handle sorted data efficiently in preprocessing pipelines.

1. Clarify the problem

Ask about input size, whether the array can contain duplicates, and if the output should be a new array or in-place. Confirm that the input is sorted in non-decreasing order.

2. Identify the O(n) approach

Recognize that squaring preserves order for non-negative numbers but reverses it for negatives. Use two pointers starting at both ends to pick the larger square and place it at the end of the result array.

3. Walk through an example

Trace the algorithm on a small array like [-4, -2, 0, 1, 3] to show how pointers move and the result is built from the back, ensuring the candidate demonstrates understanding.

4. Analyze complexity

State that the time complexity is O(n) because each element is processed once, and space complexity is O(n) for the output array. Mention that this is optimal since we must produce a new array.

5. Handle edge cases

Discuss edge cases such as empty array, single element, all negative, all positive, and duplicates. Explain how the algorithm handles them without special cases.

Key Points to Mention

  • Two-pointer technique from both ends of the array
  • Largest square comes from either the most negative or most positive element
  • Fill the result array from the end to avoid extra sorting
  • Time complexity O(n) and space complexity O(n)
  • Comparison with naive O(n log n) approach (square then sort)
  • Edge cases: empty array, single element, all negatives, all positives

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