← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Uber SWE coding round, pretty standard array problem but the follow-up tripped me up more than I expected.

Questions Asked (1)

Q1

Given a sorted array of integers that may include negative numbers, return the squares of all elements in sorted order. Follow-up: find the k-th smallest squared value.

Algorithms & Data Structures
Author's notes

The base problem I got through fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a two-pointer technique starting from both ends of the sorted array, comparing absolute values and placing the larger square at the end of the result array. For the follow-up, either extend the two-pointer approach to stop at the k-th element or use a binary search on the squared value range to find the k-th smallest square.

Pro tip: Clarify whether the input array can be modified and discuss time/space complexity trade-offs. For the follow-up, mention that binary search on the value range is O(n log(max-min)) but can be optimized to O(n) with a heap or by using the two-pointer method with early termination.

1. Understand the problem and edge cases

Confirm that the array is sorted, may contain negatives, and that the output should be sorted squares. Discuss edge cases like empty array, all negatives, all positives, and duplicates.

2. Explain the two-pointer approach for the main problem

Describe initializing two pointers at the start and end, comparing absolute values, and filling the result array from the end to the beginning. This yields O(n) time and O(n) space.

3. Address the follow-up: k-th smallest squared value

Propose either modifying the two-pointer approach to stop after k elements or using binary search on the squared value range to count how many squares are ≤ a given value, then find the k-th smallest.

4. Analyze complexity and trade-offs

Compare the two-pointer method (O(n) time, O(n) space) with binary search (O(n log(max-min)) time, O(1) space). Mention that for the follow-up, a heap can also be used but may be less efficient.

5. Write clean code and test

Implement the chosen solution, handle edge cases, and walk through a few examples to verify correctness. Discuss potential optimizations if needed.

Key Points to Mention

  • Two-pointer technique leveraging the sorted order and absolute values
  • Time and space complexity: O(n) time, O(n) space for the main problem
  • For the follow-up, binary search on the value range with counting
  • Edge cases: empty array, single element, all negative, all positive, duplicates
  • Alternative approaches: heap for k-th smallest, but O(n log k) time
  • Clarify if the input array can be modified or if extra space is allowed

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