Move zero-sale days to the end

lists

Move zero-sale days to the end

Best Buy Python Interview Question

Best Buy's store dashboard lists daily units sold. For a quick view, days with no sales should move to the end while the other days keep their order.

Write a function move_zeros(daily_units) that returns a list with every 0 moved to the end and all other numbers in their original order.

Asked of

  • Data Analyst
  • Data Engineer
  • Data Scientist
  • ML Engineer
  • AI Engineer

Example 1

Input

daily_units = [0, 1, 0, 3, 12]

Output

[1, 3, 12, 0, 0]

Example 2

Input

daily_units = [0]

Output

[0]

Explanation

In the first example, the two zero days move to the end, and 1, 3 and 12 keep their original order.

Submit also runs 3 hidden test cases that check edge cases.