← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Uber SWE coding round, one algorithmic question on squared sorted arrays. Pretty standard stuff but the two-pointer variant tripped me up more than I expected.

Questions Asked (1)

Q1

Given a sorted array of integers (possibly including negatives), return a new array of the squared values in non-decreasing order.

Algorithms & Data Structures
Author's notes

I jumped straight to the sort-after-squaring approach because my brain went blank on anything cleverer.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints and edge cases, then propose a two-pointer approach that leverages the sorted order to achieve O(n) time. Explain how the largest squares come from the extremes, and walk through the algorithm step-by-step, including handling negatives and duplicates.

Pro tip: Mention that a naive approach of squaring and sorting would be O(n log n), but the two-pointer method is optimal at O(n). Also, discuss how this approach can be extended to handle large inputs or streaming data.

1. Clarify and Confirm

Ask clarifying questions about input size, range of integers, and whether the output should be a new array or in-place. Confirm that the array is sorted in non-decreasing order.

2. Identify Optimal Strategy

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

3. Walk Through Algorithm

Explain the two-pointer process: compare absolute values at left and right, square the larger, place it at the current position in the result, and move the corresponding pointer. Continue until pointers meet.

4. Analyze Complexity

State that 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 examine each element.

5. Test with Examples

Run through a few test cases, including all negatives, all positives, mixed, and duplicates, to verify correctness and edge cases.

Key Points to Mention

  • Two-pointer technique from both ends of the array
  • Comparison based on absolute values to determine larger square
  • Filling the result array from the end to maintain non-decreasing order
  • Time complexity O(n) and space complexity O(n)
  • Handling edge cases: empty array, single element, all negatives, all positives
  • Alternative naive approach O(n log n) and why it's suboptimal

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