← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Uber SWE coding round with a two-part array problem that started reasonable and then escalated fast. The follow-up asking for O(log N) without sorting is the kind of thing that sounds doable until you're actually in the seat trying to explain it.

Questions Asked (2)

Q1

Given a sorted nondecreasing array of integers, reorder the elements by increasing absolute value (i.e. by square) in O(N) time. Elements with equal squares can appear in any order.

Algorithms & Data Structures
Author's notes

Two-pointer approach from both ends, comparing absolute values and filling a result array from the back.

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 (or squares) and placing the larger one at the end of the result array. This works because the largest absolute value must be at one of the ends, and we can fill the result from right to left in O(N) time.

Pro tip: Mention that this is essentially the merge step of merge sort applied to two sorted sequences: the non-positive part in reverse order and the non-negative part in order. This shows deeper understanding and can help handle edge cases cleanly.

1. Clarify and Confirm

Restate the problem to ensure understanding: sorted nondecreasing array, reorder by increasing absolute value (or square), O(N) time, equal squares any order. Ask if the array can contain duplicates or negative numbers (likely yes).

2. Identify Key Insight

Explain that the largest absolute value must be at either the leftmost or rightmost position because the array is sorted. This allows us to use two pointers to pick the larger absolute value and place it at the end of the result.

3. Outline Two-Pointer Algorithm

Initialize left=0, right=n-1, and a result array of size n. While left <= right, compare absolute values (or squares) of arr[left] and arr[right]; place the larger one at result[write_index] and move the corresponding pointer inward. Decrement write_index.

4. Analyze Complexity and Edge Cases

State time complexity O(N) and space O(N) for the result array. Discuss edge cases: all negative, all positive, zeros, duplicates, and empty array. Mention that if in-place is required, it's not possible without extra space due to the nature of the problem.

5. Code and Test

Write clean code with meaningful variable names. Walk through a small example (e.g., [-4,-2,0,1,3]) to demonstrate correctness. If time permits, discuss potential optimizations or alternative approaches (e.g., using squares to avoid absolute value calls).

Key Points to Mention

  • Two-pointer technique from both ends
  • Comparison based on absolute value or square
  • Filling result array from right to left (largest to smallest)
  • Time complexity O(N), space complexity O(N)
  • Handling duplicates and zeros
  • Edge cases: all negative, all positive, empty array

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

Q2

Follow-up: given the same sorted array and an integer k, return the k-th element when ordered by square value, in O(log N) time, without fully sorting by squares.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This one I did not handle well.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Recognize that the sorted array of squares forms a V-shape (or bitonic sequence) with the minimum at the element closest to zero. Use binary search to find the split point, then apply a k-th element selection algorithm on two sorted arrays (the negative and non-negative parts) in O(log N) time.

Pro tip: Mention that this is essentially finding the k-th smallest in two sorted arrays, and that you can avoid explicit square computation by comparing absolute values. Also, clarify edge cases like duplicates and k=1 or k=N.

1. Identify the structure

Explain that squaring a sorted array (with negatives) yields a sequence that decreases then increases, with the minimum at the element with smallest absolute value. The squares of the negative part (in reverse order) and the non-negative part are each sorted ascending.

2. Find the split point

Use binary search to find the index where the array transitions from negative to non-negative (or the element closest to zero). This takes O(log N) time.

3. Form two sorted arrays

Conceptually create two sorted lists: squares of the negative part in reverse order (from most negative to least negative) and squares of the non-negative part in original order. Both are sorted ascending.

4. Apply k-th element selection

Use a binary search based algorithm to find the k-th smallest element in the union of these two sorted arrays in O(log N) time, similar to finding the median of two sorted arrays.

5. Handle edge cases and verify

Discuss handling duplicates, k out of bounds, and the case where one part is empty. Walk through a small example to verify correctness.

Key Points to Mention

  • The squared array is bitonic (V-shaped) with the minimum at the element closest to zero.
  • Binary search can find the split point in O(log N).
  • The problem reduces to finding the k-th smallest in two sorted arrays, solvable in O(log N).
  • Avoid computing squares explicitly; compare absolute values to save time.
  • Edge cases: all negative, all non-negative, duplicates, k=1, k=N.
  • Time complexity: O(log N) for split + O(log N) for selection = O(log N) overall.

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