← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Uber coding screen for a software engineer role, pretty standard array manipulation problem but the follow-up is where things got interesting.

Questions Asked (1)

Q1

Given a sorted array of integers, return a new array of each element squared, also in sorted order. Then optimize it to run in O(n) time.

Algorithms & Data Structures
Author's notes

The naive approach is obvious, square everything and sort it, but that's O(n log n) and they pushed for better.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and discussing a naive approach that squares each element and sorts, which takes O(n log n) time. Then, leverage the fact that the input is sorted to design an O(n) two-pointer solution that builds the result from largest to smallest. Walk through an example to demonstrate correctness and analyze time/space complexity.

Pro tip: Emphasize that the two-pointer approach works because the largest squared values must come from either end of the sorted array, and building the result from the end avoids extra reversals. Mention edge cases like negative numbers and duplicates to show thoroughness.

1. Clarify and Confirm

Restate the problem, ask about input constraints (e.g., can elements be negative? duplicates? empty array?), and confirm expected output format.

2. Naive Approach

Describe the straightforward solution: square each element and sort the result. Analyze its time complexity as O(n log n) and note it doesn't use the sorted property.

3. Optimal Two-Pointer Approach

Explain that since the array is sorted, the largest squared values are at the ends. Use two pointers starting at both ends, compare absolute values, and place the larger square at the end of the result array, moving pointers inward.

4. Walk Through Example

Trace the algorithm on a sample array (e.g., [-4, -1, 0, 3, 10]) to show how the result is built in O(n) time and O(n) space.

5. Complexity and Edge Cases

State time complexity O(n) and space O(n) for the output. Discuss edge cases: empty array, all negatives, all positives, duplicates, and large values (overflow considerations).

Key Points to Mention

  • The input array is sorted, which allows us to use the two-pointer technique.
  • Squaring preserves order for non-negative numbers but reverses order for negative numbers.
  • The two-pointer approach compares absolute values at both ends to determine the largest square.
  • Building the result array from the end avoids the need to reverse it later.
  • Time complexity: O(n) for the optimal solution, O(n log n) for the naive approach.
  • Space complexity: O(n) for the output array; O(1) extra space if we ignore the output.

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