Move Negatives to Front Problem

Move Negatives to Front Problem — ExecCode School DSA Practice

Solve the Move Negatives to Front problem on ExecCode. Free online school DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

You are given a whole number for the problem Move Negatives to Front. Your task is to solve Move Negatives to Front. Rearrange an array of integers so that all negative numbers appear before all positive numbers. The relative order of negative numbers and positive numbers should be preserved.

Examples

Input 5 -1 2 -3 4 5; Output -1 -3 2 4 5. Input 3 1 2 3; Output 1 2 3

Constraints

1 <= N <= 10^4

Practice Move Negatives to Front free on ExecCode. Browse DSA problems, topic map, and placement guides.