PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates array manipulation and in-place algorithm skills, specifically competency in stable element reordering, index management, and space/time complexity considerations within the Coding & Algorithms domain.

  • medium
  • Uber
  • Coding & Algorithms
  • Data Scientist

Move zeros to front

Company: Uber

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given an integer array `nums`, move all `0` values to the beginning of the array **in place** while preserving the relative order of all non-zero elements. Requirements: - Modify the original array; do not allocate a second array. - Use `O(1)` extra space. - Preserve the relative order of all non-zero values. Example: - Input: `[1, 0, 2, 0, 3]` - Output: `[0, 0, 1, 2, 3]`

Quick Answer: This question evaluates array manipulation and in-place algorithm skills, specifically competency in stable element reordering, index management, and space/time complexity considerations within the Coding & Algorithms domain.

Move all zeros to the beginning while preserving the order of non-zero values.

Examples

Input: ([1, 0, 2, 0, 3],)

Expected Output: [0, 0, 1, 2, 3]

Explanation: Prompt example.

Input: ([0, 1, 0],)

Expected Output: [0, 0, 1]

Explanation: Zeros already partly front.

Input: ([1, 2],)

Expected Output: [1, 2]

Explanation: No zeros.

Input: ([],)

Expected Output: []

Explanation: Empty array.

Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Deep Equality of Two Records - Uber (medium)
  • Shortest Path in a Grid with Blocked Cells - Uber (medium)
  • Design and Implement an LRU Cache - Uber (medium)
  • Reconstruct the Alphabet Order of an Alien Language - Uber (medium)
  • Maximize Throughput and Count Trigger Components - Uber (medium)