← Uber Interview Insights

Uber·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Interviewed for a Data Scientist role at Uber and got a coding problem that felt more like a software engineering screen than anything data-related. The question was straightforward on the surface but the in-place constraint is where things get interesting.

Questions Asked (1)

Q1

Given an integer array, move all zeros to the front while keeping the relative order of the non-zero elements intact. Must be done in-place with constant extra space. What time complexity would you aim for?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

My first instinct was to just iterate from the back and swap, but preserving relative order makes that messy.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem and constraints, then propose a two-pointer solution that processes the array from right to left, moving non-zero elements to the end and filling the remaining positions with zeros. Aim for O(n) time complexity and O(1) space, and discuss potential trade-offs or alternative approaches.

Pro tip: Mention that while the problem asks for zeros at the front, a common variant is moving zeros to the end; showing awareness of both demonstrates adaptability. Also, emphasize that in-place means no additional data structures, and constant space is crucial for large datasets.

1. Clarify requirements and constraints

Confirm that the array is mutable, that relative order of non-zero elements must be preserved, and that only constant extra space is allowed. Ask about edge cases like empty arrays or all zeros.

2. Propose an efficient algorithm

Describe a two-pointer approach: iterate from the end, maintain a write pointer for non-zero elements, and after processing, fill the beginning with zeros. This achieves O(n) time and O(1) space.

3. Analyze time and space complexity

State that the algorithm runs in O(n) time because each element is visited once, and uses O(1) extra space since only a few variables are needed.

4. Discuss trade-offs and alternatives

Mention that a naive approach with extra space would be O(n) space, which is not allowed. Also, note that if the order of non-zero elements didn't need to be preserved, a simpler swap-based approach could work.

5. Test with examples and edge cases

Walk through a small example like [1,0,2,0,3] to show the step-by-step transformation to [0,0,1,2,3]. Test edge cases: empty array, all zeros, no zeros.

Key Points to Mention

  • Two-pointer technique for in-place rearrangement
  • O(n) time complexity with a single pass
  • O(1) extra space (constant space)
  • Preservation of relative order of non-zero elements
  • Edge cases: empty array, all zeros, no zeros
  • Trade-offs: alternative approaches and their complexities

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