Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Negatives before non-negatives

Python data engineering interview problem. Difficulty: beginner. Pattern: Arrays. About 8 minutes. Part of the Pro drill bank.

Move all negative numbers before the non-negative ones without changing the relative order inside either group. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

Implement partition_signs(nums: list[int]) -> list[int]. Return a new list that has all negative numbers first, then all non-negative numbers (zero counts as non-negative). Inside each group the numbers keep the order they had in the input. The input list must not change.

Requirements

  • Stable within each group.
  • Input is not modified.

Constraints

  • Values are integers.

Examples

Input: partition_signs([3, -1, 0, -5, 2]) Output: [-1, -5, 3, 0, 2] -1 stays before -5, and 3, 0, 2 keep their input order.

Topics: lakebench, python, partition, stable.

More Python interview questions · All interview problems · Learn data engineering

beginner

Negatives before non-negatives

Interview-style drill: Move all negative numbers before the non-negative ones without changing the relative order inside either group.

Implement `partition_signs(nums: list[int]) -> list[int]`. Return a new list that has all negative numbers first, then all non-negative numbers (zero counts as non-negative). Inside each group the numbers keep the order they had in the input. The input list must not change.