#K66682. Rearrange List by Negative and Non-negative Ordering

    ID: 32475 Type: Default 1000ms 256MiB

Rearrange List by Negative and Non-negative Ordering

Rearrange List by Negative and Non-negative Ordering

Given a list of integers, reorder the list such that all negative integers appear before all non-negative integers, while preserving the original relative order of the numbers in each group. For example, for the input list [-1, 2, -3, 4, 5, -6, -7, 8], the correct output is [-1, -3, -6, -7, 2, 4, 5, 8].

The challenge is to maintain the ordering stability while partitioning the list into negative and non-negative parts.

inputFormat

Input is provided via stdin as a single line containing space-separated integers. For example: -1 2 -3 4 5 -6 -7 8.

outputFormat

Output to stdout a single line of space-separated integers representing the reordered list, with all negative integers preceding non-negative ones while preserving their original relative order.## sample

-1 2 -3 4 5 -6 -7 8
-1 -3 -6 -7 2 4 5 8